cout << format("{:%T}", -10'000s); // prints: -02:46:40 cout << format("{:%H:%M:%S}", -10'000s); // prints: -02:46:40 cout << format("minutes {:%M, hours %H, seconds %S}", -10'000s); // prints: minutes -46, hours 02, seconds 40— end example
Specifier | Replacement |
%a | The locale's abbreviated weekday name. If the value does not contain a valid weekday,
an exception of type format_error is thrown. |
%A | The locale's full weekday name. If the value does not contain a valid weekday,
an exception of type format_error is thrown. |
%b | The locale's abbreviated month name. If the value does not contain a valid month,
an exception of type format_error is thrown. |
%B | The locale's full month name. If the value does not contain a valid month,
an exception of type format_error is thrown. |
%c | The locale's date and time representation. The modified command %Ec produces
the locale's alternate date and time representation. |
%C | The year divided by 100 using floored division. If the result is a single decimal digit,
it is prefixed with 0. The modified command %EC produces
the locale's alternative representation of the century. |
%d | The day of month as a decimal number. If the result is a single decimal digit,
it is prefixed with 0. The modified command %Od produces
the locale's alternative representation. |
%D | Equivalent to %m/%d/%y. |
%e | The day of month as a decimal number. If the result is a single decimal digit,
it is prefixed with a space. The modified command %Oe produces
the locale's alternative representation. |
%F | Equivalent to %Y-%m-%d. |
%g | The last two decimal digits of the ISO week-based year. If the result is a single digit it is prefixed by 0. |
%G | The ISO week-based year as a decimal number. If the result is less than four digits
it is left-padded with 0 to four digits. |
%h | Equivalent to %b. |
%H | The hour (24-hour clock) as a decimal number. If the result is a single digit,
it is prefixed with 0. The modified command %OH produces
the locale's alternative representation. |
%I | The hour (12-hour clock) as a decimal number. If the result is a single digit,
it is prefixed with 0. The modified command %OI produces
the locale's alternative representation. |
%j | If the type being formatted is a specialization of duration,
the decimal number of days without padding. Otherwise,
the day of the year as a decimal number. Jan 1 is 001. If the result is less than three digits,
it is left-padded with 0 to three digits. |
%m | The month as a decimal number. Jan is 01. If the result is a single digit, it is prefixed with 0. The modified command %Om produces
the locale's alternative representation. |
%M | The minute as a decimal number. If the result is a single digit, it is prefixed with 0. The modified command %OM produces
the locale's alternative representation. |
%n | A new-line character. |
%p | The locale's equivalent of the AM/PM designations associated with a 12-hour clock. |
%q | The duration's unit suffix as specified in [time.duration.io]. |
%Q | The duration's numeric value (as if extracted via .count()). |
%r | The locale's 12-hour clock time. |
%R | Equivalent to %H:%M. |
%S | Seconds as a decimal number. If the precision of the input cannot be exactly represented with seconds,
then the format is a decimal floating-point number with a fixed format
and a precision matching that of the precision of the input
(or to a microseconds precision if the conversion to floating-point decimal seconds
cannot be made within 18 fractional digits). The character for the decimal point is localized according to the locale. The modified command %OS produces
the locale's alternative representation. |
%t | A horizontal-tab character. |
%T | Equivalent to %H:%M:%S. |
%u | The modified command %Ou produces
the locale's alternative representation. |
%U | The week number of the year as a decimal number. The first Sunday of the year is the first day of week 01. Days of the same year prior to that are in week 00. If the result is a single digit, it is prefixed with 0. The modified command %OU produces
the locale's alternative representation. |
%V | The ISO week-based week number as a decimal number. If the result is a single digit, it is prefixed with 0. The modified command %OV produces
the locale's alternative representation. |
%w | The modified command %Ow produces
the locale's alternative representation. |
%W | The week number of the year as a decimal number. The first Monday of the year is the first day of week 01. Days of the same year prior to that are in week 00. If the result is a single digit, it is prefixed with 0. The modified command %OW produces
the locale's alternative representation. |
%x | The locale's date representation. The modified command %Ex produces
the locale's alternate date representation. |
%X | The locale's time representation. The modified command %EX produces
the locale's alternate time representation. |
%y | The last two decimal digits of the year. If the result is a single digit it is prefixed by 0. The modified command %Oy produces the locale's alternative representation. The modified command %Ey produces the locale's alternative representation
of offset from %EC (year only). |
%Y | The year as a decimal number. If the result is less than four digits
it is left-padded with 0 to four digits. The modified command %EY produces
the locale's alternative full year representation. |
%z | The offset from UTC in the ISO 8601 format. For example -0430 refers to 4 hours 30 minutes behind UTC. If the offset is zero, +0000 is used. If the offset information is not available,
an exception of type format_error is thrown. |
%Z | The time zone abbreviation. If the time zone abbreviation is not available,
an exception of type format_error is thrown. |
%% | A % character. |
string s = format("{:=>8}", 42ms); // value of s is "====42ms"— end example
template<class Duration, class charT>
struct formatter<chrono::sys_time<Duration>, charT>;
template<class Duration, class charT>
struct formatter<chrono::utc_time<Duration>, charT>;
template<class Duration, class charT>
struct formatter<chrono::tai_time<Duration>, charT>;
sys_time<Duration>{tp.time_since_epoch()} - (sys_days{1970y/January/1} - sys_days{1958y/January/1})
template<class Duration, class charT>
struct formatter<chrono::gps_time<Duration>, charT>;
sys_time<Duration>{tp.time_since_epoch()} + (sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1})
template<class Duration, class charT>
struct formatter<chrono::file_time<Duration>, charT>;
template<class Duration, class charT>
struct formatter<chrono::local_time<Duration>, charT>;
template<class Duration> struct local-time-format-t { // exposition only local_time<Duration> time; // exposition only const string* abbrev; // exposition only const seconds* offset_sec; // exposition only };
template<class Duration>
local-time-format-t<Duration>
local_time_format(local_time<Duration> time, const string* abbrev = nullptr,
const seconds* offset_sec = nullptr);
template<class Duration, class charT>
struct formatter<chrono::local-time-format-t<Duration>, charT>;
template<class Duration, class TimeZonePtr, class charT> struct formatter<chrono::zoned_time<Duration, TimeZonePtr>, charT> : formatter<chrono::local-time-format-t<Duration>, charT> { template<class FormatContext> typename FormatContext::iterator format(const chrono::zoned_time<Duration, TimeZonePtr>& tp, FormatContext& ctx); };
template<class FormatContext>
typename FormatContext::iterator
format(const chrono::zoned_time<Duration, TimeZonePtr>& tp, FormatContext& ctx);