.\" ident @(#)time_put.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH time_put 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2time_put\fP \ - A time formatting facet for output. .SH SYNOPSIS .RE .RS 0 #include .br template > .RE .RS 0 class time_put; .SH DESCRIPTION The time_put facet includes facilities for formatted output of date/time values. The member function of time_put takes a date/time in the form of a struct \f2tm\fP and translates this into a character string representation. .SH INTERFACE .br template > .RE .RS 0 class time_put : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef OutputIterator iter_type; .br explicit time_put(size_t = 0); .br iter_type put(iter_type, ios_base&, .RE .RS 15 char_type, const tm*, .br const charT*, const charT*) const; .RE .RS 1 iter_type put(iter_type, ios_base&, char_type, .RE .RS 15 const tm*, char, char = 0) const; .RE .RS 1 static locale::id id; .RE .RS 0 protected: .RE .RS 2 ~time_put(); // virtual .RE .RS 1 virtual iter_type do_put(iter_type, ios_base&, .RE .RS 26 char_type, const tm*, .br char, char) const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character the facet is instantiated on. .RE .br iter_type .RE .RS 3 Type of iterator used to scan the character buffer. .RE .SH CONSTRUCTORS .br explicit time_put(size_t refs = 0); .RE .RS 3 Constructs a time_put facet. If the \f2refs\fP argument is \f20\fP, then destruction of the object is delegated to the locale, or locales, containing it. This allows the user to ignore lifetime management issues. On the other hand, if \f2refs\fP is \f21\fP, then the object must be explicitly deleted; the locale does not do so. In this case, the object can be maintained across the lifetime of multiple locales. .RE .SH DESTRUCTORS .br ~time_put(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH FACET ID .br static locale::id id; .RE .RS 3 Unique identifier for this type of facet. .RE .SH PUBLIC MEMBER FUNCTIONS .br iter_type .br put(iter_type s, ios_base& f, .RE .RS 3 char_type fill, const tm* tmb, .br const charT* pattern, const charT* pat_end) const; .RE .RS 3 Creates a character string representing the Date/Time contained in \f2tmb\fP. The format of the string is determined by a sequence of format modifiers contained in the range \f2[pattern,pat_end)\fP. These modifiers are from the same set as those used by the \f2strftime\fP function and are applied in exactly the same way. The resulting string is written out to the buffer pointed to by the iterator \f2s\fP. See the table below for a description of \f2strftime\fP formatting characters. The \f2fill\fP argument is used for any padding. Returns an iterator pointing one past the last character written. .RE .SH PROTECTED MEMBER FUNCTIONS .RE .RS 0 iter_type .br do_put(iter_type s, ios_base& f, char_type fill, .RE .RS 3 const tm* tmb, char format, char modifier = 0) const; .RE .RS 3 Calls the protected virtual \f2do_put\fP function. Writes out a character string representation of the Date/Time contained in \f2t\fP. The string is formatted according the specifier \f2format\fP and modifier \f2modifier\fP. These values are interpreted in exactly the same way as the \f2strftime\fP function interprets its format and modifier flags. See the table below for a description of \f2strftime\fP formatting characters. The \f2fill\fP argument is used for any padding. Returns an iterator pointing one past the last character written. .RE Table 1 -- Formatting characters used by strftime(). For those formats that do not use all members of the struct tm, only those members that are actually used are noted [in brackets]. FORMAT MEANING EXAMPLE .br CHARACTER \f2a\fP \f2Abbreviated weekday name \f2Sun\fP .br [from tm::tm_wday]\fP \f2A\fP \f2Full weekday name \f2Sunday\fP .br [from tm::tm_wday]\fP \f2b\fP \f2Abbreviated month name \fP \f2Feb\fP \f2B\fP \f2Full month name \fP \f2February\fP \f2c\fP \f2Date and time \f2Feb 29 .br [may use all members]\fP 14:34:56 1984\fP \f2d\fP \f2Day of the month\fP \f229\fP \f2H\fP \f2Hour of the 24-hour day\fP \f214\fP \f2I\fP \f2Hour of the 12-hour day\fP \f202\fP \f2j\fP \f2Day of the year, from 001 \f260\fP .br [from tm::tm_yday]\fP \f2m\fP \f2Month of the year, from 01\fP \f202\fP \f2M\fP \f2Minutes after the hour\fP \f234\fP \f2p\fP \f2AM/PM indicator, if any\fP \f2AM\fP \f2S\fP \f2Seconds after the minute\fP \f256\fP \f2U\fP \f2Sunday week of the year, \f2\fP .br from 00 [from tm::tm_yday and .br tm::tm_wday]\fP \f2w\fP \f2Day of the week, with 0 \f20\fP .br for Sunday\fP \f2W\fP \f2Monday week of the year, \f2\fP .br from 00 [from tm::tm_yday and .br tm::tm_wday]\fP \f2x\fP \f2Date [uses tm::tm_yday \f2Feb 29 1984\fP .br in some locales]\fP \f2X\fP \f2Time\fP \f214:34:56\fP \f2y\fP \f2Year of the century, \f284\fP .br from 00 (deprecated) \fP \f2Y\fP \f2Year\fP \f21984\fP \f2Z\fP \f2Time zone name \f2PST or PDT\fP .br [from tm::tm_isdst]\fP .SH EXAMPLE .RE .RS 0 // .br // timeput.cpp .br // .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 1 typedef ostreambuf_iterator > .RE .RS 9 iter_type; .RE .RS 2 .RE .RS 1 locale loc; .br time_t tm = time(NULL); .br struct tm* tmb = localtime(&tm); .br struct tm timeb; .br memcpy(&timeb,tmb,sizeof(struct tm)); .br char pat[] = "%c"; .RE .RS 0 .RE .RS 2 // Get a time_put facet .RE .RS 1 const time_put& tp = .RE .RS 0 #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE .RE .RS 1 use_facet >(loc); .RE .RS 0 #else .RE .RS 1 use_facet(loc,(time_put*)0); .RE .RS 0 #endif .br .RE .RS 2 // Construct a ostreambuf_iterator on cout .RE .RS 1 iter_type begin(cout); .RE .RS 2 .RE .RS 1 cout << " --> "; .br tp.put(begin,cout,' ',&timeb,pat,pat+2); .br .br cout << endl << " --> "; .br tp.put(begin,cout,' ',&timeb,'c',' '); .RE .RS 0 .RE .RS 1 cout << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, time_get