time_put class template — Facet for output of dates and times
template <typename charT, typename OutputIterator = ostreambuf_iterator<charT> > class time_put : public locale::facet { public: typedef charT char_type; typedef OutputIterator iter_type; explicit time_put(size_t refs = 0); iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb, const charT* pattern, const charT* pat_end) const; iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb, char format, char modifier = 0) const; static locale::id id; protected: virtual ~time_put( ); virtual iter_type do_put(iter_type s, ios_base&, char_type, const tm* t, char format, char modifier) const; };
The time_put
class template
is a facet for formatting and writing dates and times. The time_put<char>
and time_put<wchar_t>
instantiations are
standard.
Note that time_put
is
unlike other facets. The public put
function does not always directly call
do_put
. Here are the complete
descriptions of put
and do_put
:
iter_type
put
(iter_type out, ios_base& stream,
char_type fill, const tm* t, const charT* pattern, const charT*
pat_end) const
Reads the pattern in [pattern
, pat_end
) and writes formatted date
and time information to out
. The pattern contains ordinary
characters (which are written directly to out
) interspersed with format
specifiers. A format specifier starts with '%
' and is followed by an optional
modifier character, which is followed in turn by a format
specifier character. The put
function checks format
characters by first calling narrow
from the ctype<charT>
facet, then
checking the narrowed character.
For each format specifier, put
calls do_put(out
, stream
, fill
, t
, format
, modifier)
, in which format
is the format specifier and
modifier
is the modifier
character or 0
if no
modifier is present.
The use of modifier characters is
implementation-defined. The standard does not define any
modifiers. See the do_put
member function for more information.
iter_type
put
(iter_type out, ios_base& stream,
char_type fill, const tm* t, char format, char modifier = 0)
const
Returns do_put(out
,
stream
, fill
, t
, format
, modifier)
.
virtual iter_type
do_put
(iter_type out,
ios_base& stream
, char_type fill, const tm* t, char format, char
modifier) const
Formats a single date or time element and writes the
formatted characters to out
. The format
character specifies what to
output (as shown in Table 13-22). The
date and time information is obtained from t
.
The do_put
function,
unlike some of the other output facets, does not use stream
's flags or field width. The
fill
parameter is used by
implementation-defined formatting.
Table 13-22. Format specifiers for do_put
Specifier | Description |
---|---|
| Abbreviated weekday name |
| Full weekday name |
| Abbreviated month name |
| Full month name |
| Complete date and time |
| Day of the month ( |
| Hour ( |
| Hour ( |
| Day of the year ( |
| Month ( |
| Minutes ( |
| A.M./P.M. designation for use with a 12-hour clock |
| Second ( |
| Week number ( |
| Weekday ( |
| Week number ( |
| Date |
| Time |
| Year in century ( |
| Year |
| Time zone name or abbreviation, or empty string if time zone is unknown |
| Literal |
The use of modifier
is
implementation-defined. The C++ standard recommends the use of
POSIX modifiers, which are 'E
'
and 'O
'. These modifiers
request the use of an alternative format if the locale has one.
The 'E
' modifier applies to
certain format specifiers to request an alternative representation
for dates and times. The 'O
'
modifier applies to certain format specifiers to request the use
of alternative numeric symbols. If a locale cannot honor the
modified request, it uses the unmodified format specifier.