< cpp‎ | locale
Revision as of 17:53, 2 November 2012 by P12bot (Talk | contribs)


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

Defined in header <locale>

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

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

    class CharT,
    class InputIt = std::istreambuf_iterator<CharT>

> class time_get;

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

Class template std::time_get encapsulates date and time parsing rules. The I/O manipulator std::get_time uses the std::time_get facet of the I/O stream's locale to convert text input to a std::tm object.

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

Inheritance diagram


Type requirements

InputIt must meet the requirements of InputIterator.


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_get<char> parses narrow string representations of date and time
std::time_get<wchar_t> parses wide string representations of date and time
std::time_get<char, InputIt> parses narrow string representations of date and time using custom input iterator
std::time_get<wchar_t, InputIt> parses wide string representations of date and time using custom input iterator

Member types

Member type Definition
char_type CharT
iter_type InputIt

Member functions

Template:cpp/locale/time get/dcl list date orderTemplate:cpp/locale/time get/dcl list get timeTemplate:cpp/locale/time get/dcl list get dateTemplate:cpp/locale/time get/dcl list get weekdayTemplate:cpp/locale/time get/dcl list get monthnameTemplate:cpp/locale/time get/dcl list get yearTemplate:cpp/locale/time get/dcl list get
constructs a new time_get facet
(public member function)
destructs a time_get facet
(protected member function)

Member objects

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

Protected member functions

Template:cpp/locale/time get/dcl list do date orderTemplate:cpp/locale/time get/dcl list do get timeTemplate:cpp/locale/time get/dcl list do get dateTemplate:cpp/locale/time get/dcl list do get weekdayTemplate:cpp/locale/time get/dcl list do get monthnameTemplate:cpp/locale/time get/dcl list do get yearTemplate:cpp/locale/time get/dcl list do get

Inherited from std::time_base

Type Definition
dateorder date order enumeration type, defining the values no_order, dmy, mdy, ymd, and ydm


#include <iostream>
#include <sstream>
#include <string>
#include <locale>
#include <ctime>
#include <iomanip>
int main()
    std::wstring input = L"2011-Februar-18 23:12:34";
    std::tm t;
    std::wistringstream ss(input);
    ss >> std::get_time(&t, L"%Y-%b-%d %H:%M:%S"); // uses std::time_get<wchar_t>
    std::cout << std::asctime(&t);


Sun Feb 18 23:12:34 2011

See also

formats contents of struct std::tm for output as character sequence
(class template)
parses a date/time value of specified format
(function template)