Outputting Date and Time in C++ using std::chrono
问题 I have been upgrading some old code and have been trying to update to c++11 where possible. The following code is how I used to display the time and date in my program #include <iostream> #include <string> #include <stdio.h> #include <time.h> const std::string return_current_time_and_date() const { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct); return buf; } I would like to output the current time and