(C++) std::ctime
January 10, 2018 · View on GitHub
(C++) std::ctime
std::ctime is an STL function to convert std::time_t to std::string.
#include <ctime> #include <iostream> #include <string> int main() { //Create a time struct std::time_t t; //Set the time struct to the current time std::time(&t); //Convert the time struct to std::string const std::string s = std::ctime(&t); //Put the time std::string on screen std::cout << s << '\n'; }
Screen output:
Mon Aug 2 12:37:32 2010