I want understand how to work std::put_time, and how can I get date stamp in "YYYY/MM/DD HH:MM:SS" format. Now I write somthing like this:
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::time_t now_c = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24));
std::cout << std::put_time(std::localtime(&now_c), "%F %T") << '\n';
and output is 2011-10-25 12:00:08, how can I get the date as 2011/10/25 12:00:08.
As mentioned 1 hour ago here, cppreference has good documentation on this: http://en.cppreference.com/w/cpp/io/manip/put_time
Specifically, you can get the format you described using the following format string:
std::cout << std::put_time(std::localtime(&now_c), "%Y/%m/%d %T")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With