Namespaces
Variants
Views
Actions

Template:cpp/chrono/format spec begin

From cppreference.com

The format specification has the form

fill-and-align (optional) width (optional) precision (optional) L(optional) chrono-spec (optional)

fill-and-align, width, and precision have the same meaning as in standard format specification. precision is valid only for std::chrono::duration types where the representation type Rep is a floating-point type, otherwise std::format_error is thrown.

The locale used for formatting is determined as follows:

  • the default "C" locale if L is not present in the format specification,
  • otherwise, the locale denoted by the std::locale passed to the formatting function, if any,
  • otherwise (L is present but no std::locale is passed to the formatting function), the global locale.

If the (ordinary or wide) string literal encoding is a Unicode encoding form and the locale is among an implementation-defined set of locales, each replacement that depends on the locale is performed as if the replacement character sequence is converted to the literal encoding.

The chrono-spec consists of one or more conversion specifiers and ordinary characters (other than {, }, and %). A chrono-spec must start with a conversion specifier. All ordinary characters are written to the output without modification. Each unmodified conversion specifier begins with a % character followed by a character that determines the behavior of the specifier. Some conversion specifiers have a modified form in which an E or O modifier character is inserted after the % character. Each conversion specifier is replaced by appropriate characters in the output as described below.

If the chrono-spec is empty, the chrono object is formatted as if by streaming it to an object os of type std::basic_ostringstream<CharT> with the formatting locale (one of std::locale::classic(), the passed std::locale object, and std::locale::global()) imbued and copying os.str() to the output buffer with additional padding and adjustments as per format specifiers.

The following format specifiers are available:

Conversion
specifier
Explanation
%% Writes a literal % character.
%n Writes a newline character.
%t Writes a horizontal tab character.