< cpp‎ | locale
Localizations library
Locales and facets
Facet category base classes
ctype facets
numeric facets
collate facets
time facets
monetary facets
messages facets
Character classification and conversion
Character classification
Code conversion facets
C locale
Defined in header <locale>

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

> class time_get;

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

Inheritance diagram

If a std::time_get specialization is not guaranteed to be provided by the standard library (see below), the behaviors of its member functions (except the constructor and destructor) are not guaranteed as specified.


[edit] Specializations

The standard library is guaranteed to provide the following specializations (they are required to be implemented by any locale object):

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

In addition, the standard library is also guaranteed to provide every specialization that satisfies the following type requirements:

  • CharT is one of char and wchar_t, and
  • InputIt must meet the requirements of LegacyInputIterator.

[edit] Member types

Member type Definition
char_type CharT
iter_type InputIt

[edit] Member functions

constructs a new time_get facet
(public member function)
destructs a time_get facet
(protected member function)
invokes do_date_order
(public member function) [edit]
invokes do_get_time
(public member function) [edit]
invokes do_get_date
(public member function) [edit]
invokes do_get_weekday
(public member function) [edit]
invokes do_get_monthname
(public member function) [edit]
invokes do_get_year
(public member function) [edit]
invokes do_get
(public member function) [edit]

[edit] Member objects

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

[edit] Protected member functions

obtains preferred ordering of day, month, and year
(virtual protected member function) [edit]
extracts hours, minutes, and seconds from input stream
(virtual protected member function) [edit]
extracts month, day, and year from input stream
(virtual protected member function) [edit]
extracts the name of a day of the week from input stream
(virtual protected member function) [edit]
extracts a month name from input stream
(virtual protected member function) [edit]
extracts a year from input stream
(virtual protected member function) [edit]
[virtual] (C++11)
extracts date/time components from input stream, according to the specified format
(virtual protected member function) [edit]

Inherited from std::time_base

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

[edit] Example

Note: choose clang to observe the output. libstdc++ does not correctly implement the %b specifier: bug 78714

#include <iostream>
#include <sstream>
#include <locale>
#include <iomanip>
int main()
    std::tm t = {};
    std::istringstream ss("2011-Februar-18 23:12:34");
    ss >> std::get_time(&t, "%Y-%b-%d %H:%M:%S");
    if (
        std::cout << "Parse failed\n";
        std::cout << std::put_time(&t, "%c") << '\n';

Possible output:

Sun Feb 18 23:12:34 2011

[edit] See also

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