Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/time get"

From cppreference.com
< cpp‎ | locale
m (simplify)
m (Text replace - "par req concept" to "par req named")
Line 17: Line 17:
 
===Type requirements===
 
===Type requirements===
 
{{par begin}}
 
{{par begin}}
{{par req concept | InputIt | InputIterator}}
+
{{par req named | InputIt | InputIterator}}
 
{{par end}}
 
{{par end}}
  

Revision as of 15:02, 15 June 2018

 
 
 
 
Defined in header <locale>
template<

    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

Contents

Type requirements

-
InputIt must meet the requirements of LegacyInputIterator.

Specializations

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

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

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

Member types

Member type Definition
char_type CharT
iter_type InputIt

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]
(C++11)
invokes do_get
(public member function) [edit]

Member objects

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

Protected member functions

obtains preferred ordering of day, month, and year
(virtual protected member function) [edit]
[virtual]
extracts hours, minutes, and seconds from input stream
(virtual protected member function) [edit]
[virtual]
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]
[virtual]
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

Example

#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.imbue(std::locale("de_DE"));
    ss >> std::get_time(&t, L"%Y-%b-%d %H:%M:%S"); // uses std::time_get<wchar_t>
    std::cout << std::asctime(&t);
}

Output:

Sun Feb 18 23:12:34 2011

See also

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