<chrono>
is not a library for formatting datetimes into strings. It is useful for converting different time representations (milliseconds to days, etc), adding timestamps together and such.
The only datetime formatting functions in the standard library are the ones inherited from the C standard library, including the std::strftime
which you already used in the "C(-ish)" version. EDIT: As pointed out by jaggedSpire, C++11 introduced std::put_time
. It provides a convenient way to stream formatted dates with the same API as used by the C functions.
Since std::gmtime
(and std::localtime
if you were to use that) take their argument as a unix timestamp, you don't need <chrono>
to convert the time. It is already in the correct representation. Only the underlying type must be converted from std::uint32_t
to std::time_t
. That is not implemented portably in your C version.
A portable way to convert the timestamp, with std::put_time
based formatting:
std::uint32_t time_date_stamp = 1484693089;
std::time_t temp = time_date_stamp;
std::tm* t = std::gmtime(&temp);
std::stringstream ss; // or if you're going to print, just input directly into the output stream
ss << std::put_time(t, "%Y-%m-%d %I:%M:%S %p");
std::string output = ss.str();