Namespaces
Variants
Views
Actions

std::time_put

From cppreference.com
< cpp‎ | locale
Revision as of 18:47, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
template<

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

> class time_put;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

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

Type requirements

-
OutputIt must meet the requirements of OutputIterator.

Specializations

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, 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

Member types

Member type Definition
char_type CharT
iter_type OutputIt

Member functions

Template:cpp/locale/time put/dcl list constructorTemplate:cpp/locale/time put/dcl list destructorTemplate:cpp/locale/time put/dcl list put

Member objects

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

Protected member functions

Template:cpp/locale/time put/dcl list do put

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秒

See also

Template:cpp/locale/dcl list time put bynameTemplate:cpp/locale/dcl list time getTemplate:cpp/io/manip/dcl list put time