Difference between revisions of "cpp/locale/time put byname"
From cppreference.com
m (Shorten template names. Use {{lc}} where appropriate.) |
|||
Line 1: | Line 1: | ||
{{cpp/title | time_put_byname}} | {{cpp/title | time_put_byname}} | ||
{{cpp/locale/navbar}} | {{cpp/locale/navbar}} | ||
− | {{ | + | {{dcl begin}} |
− | {{ | + | {{dcl header | locale}} |
− | {{ | + | {{dcl | 1= |
template< class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> > | template< class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> > | ||
class time_put_byname : public std::time_put<CharT, OutputIterator>; | class time_put_byname : public std::time_put<CharT, OutputIterator>; | ||
}} | }} | ||
− | {{ | + | {{dcl end}} |
− | {{ | + | {{lc|std::time_put_byname}} is a {{lc|std::time_put}} facet which encapsulates time and date formatting rules of the locale specified at its construction. |
Two specializations are provided by the standard library | Two specializations are provided by the standard library | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc header | locale }} |
− | {{ | + | {{dsc | {{c|std::time_put_byname<char, OutputIterator>}} | narrow/multibyte time formatting }} |
− | {{ | + | {{dsc | {{c|std::time_put_byname<wchar_t, OutputIterator>}} | wide string time formatting }} |
− | {{ | + | {{dsc end}} |
===Member types=== | ===Member types=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc hitem | Member type | Definition}} |
− | {{ | + | {{dsc | {{tt|char_type}} | {{tt|CharT}}}} |
− | {{ | + | {{dsc | {{tt|iter_type}} | {{tt|OutputIterator}}}} |
− | {{ | + | {{dsc end}} |
===Member functions=== | ===Member functions=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc mem ctor | cpp/locale/time_put_byname/time_put_byname | constructs a new time_put_byname facet }} |
− | {{ | + | {{dsc prot mem dtor | cpp/locale/time_put_byname/~time_put_byname | destructs a time_put_byname facet }} |
− | {{ | + | {{dsc end}} |
{{cpp/locale/time_put/inherit}} | {{cpp/locale/time_put/inherit}} | ||
Line 69: | Line 69: | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc | cpp/locale/dcl list time_put}} |
− | {{ | + | {{dsc end}} |
[[de:cpp/locale/time put byname]] | [[de:cpp/locale/time put byname]] |
Revision as of 19:11, 31 May 2013
Defined in header <locale>
|
||
template< class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> > class time_put_byname : public std::time_put<CharT, OutputIterator>; |
||
std::time_put_byname is a std::time_put facet which encapsulates time and date formatting rules of the locale specified at its construction.
Two specializations are provided by the standard library
Defined in header
<locale> | |
std::time_put_byname<char, OutputIterator> | narrow/multibyte time formatting |
std::time_put_byname<wchar_t, OutputIterator> | wide string time formatting |
Contents |
Member types
Member type | Definition |
char_type
|
CharT
|
iter_type
|
OutputIterator
|
Member functions
constructs a new time_put_byname facet (public member function) | |
destructs a time_put_byname facet (protected member function) |
Inherited from std::time_put
Member objects
Member name | Type |
id (static)
|
std::locale::id |
Member functions
invokes do_put (public member function of std::time_put<CharT,OutputIt> )
|
Protected member functions
[virtual] |
formats date/time and writes to output stream (virtual protected member function of std::time_put<CharT,OutputIt> )
|
Example
This example prints current time using the "C" locale with the time_put facet replaced by various time_put_byname facets
Run this code
#include <iostream> #include <ctime> #include <iomanip> #include <codecvt> int main() { std::time_t t = std::time(NULL); std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf()); std::wostream out(&conv); out.imbue(std::locale(out.getloc(), new std::time_put_byname<wchar_t>("ja_JP"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; out.imbue(std::locale(out.getloc(), new std::time_put_byname<wchar_t>("ru_RU.utf8"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; out.imbue(std::locale(out.getloc(), new std::time_put_byname<wchar_t>("sv_SE.utf8"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; }
Possible output:
木曜日 2012年08月09日 21時41分02秒 Четверг Чт. 09 авг. 2012 21:41:02 torsdag tor 9 aug 2012 21:41:02