Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | locale
(fmt)
(fix links)
Line 42: Line 42:
 
{{dcl list mem ctor | cpp/locale/time_get/time_get | constructs a new time_get facet }}
 
{{dcl list mem ctor | cpp/locale/time_get/time_get | constructs a new time_get facet }}
 
{{dcl list prot mem dtor | cpp/locale/time_get/~time_get | destructs a time_get facet }}
 
{{dcl list prot mem dtor | cpp/locale/time_get/~time_get | destructs a time_get facet }}
{{dcl list mem fun | cpp/locale/time_get/do_date_order | title=date_order | invokes {{tt|do_date_order}} }}
+
{{dcl list mem fun | cpp/locale/time_get/date_order | invokes {{tt|do_date_order}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get_time | title=get_time | invokes {{tt|do_get_time}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get_time | invokes {{tt|do_get_time}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get_date | title=get_date | invokes {{tt|do_get_date}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get_date | invokes {{tt|do_get_date}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get_weekday | title=get_weekday | invokes {{tt|do_get_weekday}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get_weekday | invokes {{tt|do_get_weekday}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get_monthname | title=get_monthname | invokes {{tt|do_get_monthname}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get_monthname | invokes {{tt|do_get_monthname}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get_year | title=get_year | invokes {{tt|do_get_year}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get_year | invokes {{tt|do_get_year}} }}
{{dcl list mem fun | cpp/locale/time_get/do_get | title=get | invokes {{tt|do_get}} }}
+
{{dcl list mem fun | cpp/locale/time_get/get | invokes {{tt|do_get}} }}
 
{{dcl list end}}
 
{{dcl list end}}
  
Line 58: Line 58:
 
===Protected member functions===
 
===Protected member functions===
 
{{dcl list begin}}
 
{{dcl list begin}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_date_order | obtains preferred ordering of day, month, and year}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/date_order | title=do_date_order| obtains preferred ordering of day, month, and year}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get_time | extracts hours, minutes, and seconds from input stream}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get_time | title=do_get_time | extracts hours, minutes, and seconds from input stream}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get_date  | extracts month, day, and year from input stream}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get_date | title=do_get_date  | extracts month, day, and year from input stream}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get_weekday | extracts the name of a day of the week from input stream}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get_weekday | title=do_get_weekday | extracts the name of a day of the week from input stream}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get_monthname | extacts a month name from input stream}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get_monthname | title=do_get_monthname | extacts a month name from input stream}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get_year | extracts a year from input stream}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get_year | title=do_get_year | extracts a year from input stream}}
{{dcl list prot mem vfun | cpp/locale/time_get/do_get | extracts date/time components from input stream, according to the specified format}}
+
{{dcl list prot mem vfun | cpp/locale/time_get/get | title=do_get | extracts date/time components from input stream, according to the specified format}}
 
{{dcl list end}}
 
{{dcl list end}}
  

Revision as of 10:46, 12 October 2012

 
 
 
 

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

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

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

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

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

> class time_get;
</td>

<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

Inheritance diagram

Contents

Type requirements

-
InputIt must meet the requirements of LegacyInputIterator.

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

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)

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)
[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)
extracts the name of a day of the week from input stream
(virtual protected member function)
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

#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)