25 Time library [time]

25.5 Class template duration [time.duration]

25.5.10 I/O [time.duration.io]

template<class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d);
Requires: Rep is an integral type whose integer conversion rank ([conv.rank]) is greater than or equal to that of short, or a floating point type.
charT is char or wchar_­t.
Effects: Forms a basic_­string<charT, traits> from d.count() using to_­string if charT is char, or to_­wstring if charT is wchar_­t.
Appends the units suffix described below to the basic_­string.
Inserts the resulting basic_­string into os.
[ Note
:
This specification ensures that the result of this streaming operation will obey the width and alignment properties of the stream.
— end note
 ]
The units suffix depends on the type Period​::​type as follows:
  • If Period​::​type is atto, the suffix is "as".
  • Otherwise, if Period​::​type is femto, the suffix is "fs".
  • Otherwise, if Period​::​type is pico, the suffix is "ps".
  • Otherwise, if Period​::​type is nano, the suffix is "ns".
  • Otherwise, if Period​::​type is micro, the suffix is "Ξs" ("\u00b5\u0073").
  • Otherwise, if Period​::​type is milli, the suffix is "ms".
  • Otherwise, if Period​::​type is centi, the suffix is "cs".
  • Otherwise, if Period​::​type is deci, the suffix is "ds".
  • Otherwise, if Period​::​type is ratio<1>, the suffix is "s".
  • Otherwise, if Period​::​type is deca, the suffix is "das".
  • Otherwise, if Period​::​type is hecto, the suffix is "hs".
  • Otherwise, if Period​::​type is kilo, the suffix is "ks".
  • Otherwise, if Period​::​type is mega, the suffix is "Ms".
  • Otherwise, if Period​::​type is giga, the suffix is "Gs".
  • Otherwise, if Period​::​type is tera, the suffix is "Ts".
  • Otherwise, if Period​::​type is peta, the suffix is "Ps".
  • Otherwise, if Period​::​type is exa, the suffix is "Es".
  • Otherwise, if Period​::​type is ratio<60>, the suffix is "min".
  • Otherwise, if Period​::​type is ratio<3600>, the suffix is "h".
  • Otherwise, if Period​::​type​::​den == 1, the suffix is "[num]s".
  • Otherwise, the suffix is "[num/den]s".
In the list above the use of num and den refer to the static data members of Period​::​type, which are converted to arrays of charT using a decimal conversion with no leading zeroes.
If Period​::​type is micro, but the character U+00B5 cannot be represented in the encoding used for charT, the unit suffix "us" is used instead of "Ξs".
Returns: os.
template<class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const duration<Rep, Period>& d);
Effects: Streams d into os using the format specified by the NTCTS fmt.
fmt encoding follows the rules specified in [time.format].
Returns: os.
template<class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, duration<Rep, Period>& d, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr);
Effects: Attempts to parse the input stream is into the duration d using the format flags given in the NTCTS fmt as specified in [time.parse].
If the parse parses everything specified by the parsing format flags without error, and yet none of the flags impacts a duration, d will be assigned a zero value.
If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null.
If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null.
Returns: is.