std::time_put

From cppreference.com
Defined in header <locale>
template<

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

> class time_put : public std::locale::facet;

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

Two specializations and two partial specializations are provided by the standard library and are implemented by all locale objects created in a C++ program:

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, OutputIterator> creates narrow string representations of date and time using custom output iterator
std::time_put<wchar_t, OutputIterator> creates wide string representations of date and time using custom output iterator

Contents

[edit] Member types

Member type Definition
char_type charT
iter_type OutputIterator

[edit] Member objects

Member name Type
id (static) std::locale::id

[edit] Member functions

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

[edit] Protected member functions

[virtual]
formats date/time and writes to output stream
(virtual protected member function of std::time_get)

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

Output:

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

[edit] See also

parses time/date values from an input character sequence into struct std::tm
(class template)
(C++11)
formats and outputs a date/time value according to the specified format
(function template)