Namespaces
Variants
Views
Actions

std::time_put

From cppreference.com
< cpp‎ | locale
Revision as of 10:23, 7 October 2013 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Defined in header <locale>
template<

    class CharT,
    class OutputIt = std::ostreambuf_iterator<CharT>

> class time_put;

Class template std::time_put encapsulates date and time formatting rules. The I/O manipulator std::put_time uses the std::time_put facet of the I/O stream's locale to generate text representation of an std::tm object.

cpp/locale/time basecpp/locale/locale/facetstd-time put-inheritance.svg
About this image

Inheritance diagram

Contents

[edit] Type requirements

-
OutputIt must meet the requirements of OutputIterator.

[edit] Specializations

Two standalone (locale-independent) full specializations and two partial specializations are provided by the standard library:

Defined in header <locale>
std::time_put<char> creates narrow string representations of date and time
std::time_put<wchar_t> creates wide string representations of date and time
std::time_put<char, OutputIt> creates narrow string representations of date and time using custom output iterator
std::time_put<wchar_t, OutputIt> creates wide string representations of date and time using custom output iterator

In addition, every locale object constructed in a C++ program implements its own (locale-specific) versions of these specializations.

[edit] Member types

Member type Definition
char_type CharT
iter_type OutputIt

[edit] Member functions

constructs a new time_put facet
(public member function) [edit]
destructs a time_put facet
(protected member function) [edit]
invokes do_put
(public member function) [edit]

[edit] Member objects

static std::locale::id id
id of the locale
(public member object)

[edit] Protected member functions

[virtual]
formats date/time and writes to output stream
(virtual protected member function) [edit]

[edit] Example

#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("ja_JP"));
    // this I/O manipulator std::put_time uses std::time_put<wchar_t>
    out << std::put_time(std::localtime(&t), L"%A %c") << '\n';
}

Output:

水曜日 2011年11月09日 12時32分05秒

[edit] See also

represents the system-supplied std::time_put for the named locale
(class template) [edit]
parses time/date values from an input character sequence into struct std::tm
(class template) [edit]
(C++11)
formats and outputs a date/time value according to the specified format
(function template) [edit]