Topilski Alexandr
Topilski Alexandr

Reputation: 669

std::put_time formats

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.

Upvotes: 3

Views: 19828

Answers (2)

jogojapan
jogojapan

Reputation: 69977

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")

Upvotes: 11

Some programmer dude
Some programmer dude

Reputation: 409196

See this reference. It's actually the same as for the old strftime function, with some extra formats thrown in.

Upvotes: 2

Related Questions