Difference between revisions of "cpp/locale/time get"
From cppreference.com
m (Text replace - "{{tdcl list end" to "{{dcl list end") |
m (Text replace - "{{tdcl" to "{{dcl") |
||
Line 14: | Line 14: | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{ | + | {{dcl list header | locale }} |
− | {{ | + | {{dcl list item | {{c|std::time_get<char>}} | parses narrow string representations of date and time }} |
− | {{ | + | {{dcl list item | {{c|std::time_get<wchar_t>}} | parses wide string representations of date and time }} |
− | {{ | + | {{dcl list item | {{c|std::time_get<char, InputIterator>}} | parses narrow string representations of date and time using custom input iterator}} |
− | {{ | + | {{dcl list item | {{c|std::time_get<wchar_t, InputIterator>}} | parses wide string representations of date and time using custom input iterator}} |
{{dcl list end}} | {{dcl list end}} | ||
===Member types=== | ===Member types=== | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{ | + | {{dcl list hitem | Member type | Definition}} |
− | {{ | + | {{dcl list item | {{tt|char_type}} | {{tt|charT}}}} |
− | {{ | + | {{dcl list item | {{tt|iter_type}} | {{tt|InputIterator}}}} |
{{dcl list end}} | {{dcl list end}} | ||
===Member objects=== | ===Member objects=== | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{ | + | {{dcl list hitem | Member name | Type}} |
− | {{ | + | {{dcl list item | {{tt|id}} {{mark|static}} | {{c|std::locale::id}} }} |
{{dcl list end}} | {{dcl list end}} | ||
Line 60: | Line 60: | ||
{{ inherited | {{small|std::}}time_base | | {{ inherited | {{small|std::}}time_base | | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{ | + | {{dcl list hitem | Type | Definition}} |
− | {{ | + | {{dcl list item | {{tt|dateorder}} | date order enumeration type, defining the values {{tt|no_order}}, {{tt|dmy}}, {{tt|mdy}}, {{tt|ymd}}, and {{tt|ydm}}}} |
{{dcl list end}} | {{dcl list end}} | ||
}} | }} |
Revision as of 01:38, 12 June 2012
Template:cpp/locale/time get/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td>Defined in header
</td>
<locale>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad">template< class charT, class InputIterator = std::istreambuf_iterator<charT> >
class time_get : public std::locale::facet, public std::time_base;
</td>
class time_get : public std::locale::facet, public std::time_base;
<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.
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, InputIterator> | parses narrow string representations of date and time using custom input iterator |
std::time_get<wchar_t, InputIterator> | parses wide string representations of date and time using custom input iterator |
Contents |
Member types
Member type | Definition |
char_type
|
charT
|
iter_type
|
InputIterator
|
Member objects
Member name | Type |
id (static)
|
std::locale::id |
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) | |
invokes do_get_time (public member function) | |
invokes do_get_date (public member function) | |
invokes do_get_weekday (public member function) | |
invokes do_get_monthname (public member function) | |
invokes do_get_year (public member function) | |
invokes do_get (public member function) |
Protected member functions
[virtual] |
obtains preferred ordering of day, month, and year (virtual protected member function) |
[virtual] |
extracts hours, minutes, and seconds from input stream (virtual protected member function) |
[virtual] |
extracts month, day, and year from input stream (virtual protected member function) |
[virtual] |
extracts the name of a day of the week from input stream (virtual protected member function) |
[virtual] |
extacts a month name from input stream (virtual protected member function) |
[virtual] |
extracts a year from input stream (virtual protected member function) |
[virtual] |
extracts date/time components from input stream, according to the specified format (virtual protected member function) |
Inherited from std::time_base
Type | Definition |
dateorder
|
date order enumeration type, defining the values no_order , dmy , mdy , ymd , and ydm
|
Example
Run this code
#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 struct std::tm for output as character sequence (class template) | |
(C++11) |
parses a date/time value of specified format (function template) |