Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::time_get

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
       
      Defined in header<locale>
      template<

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

      >class time_get;

      Class templatestd::time_get encapsulates date and time parsing rules. The I/O manipulatorstd::get_time uses thestd::time_get facet of the I/O stream's locale to convert text input to astd::tm object.

      std-time get-inheritance.svg

      If astd::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.

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide the following specializations (they arerequired 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:

      [edit]Nested types

      Type Definition
      char_typeCharT
      iter_typeInputIt

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      [edit]Member functions

      constructs a newtime_get facet
      (public member function)
      destructs atime_get facet
      (protected member function)
      invokesdo_date_order
      (public member function)[edit]
      invokesdo_get_time
      (public member function)[edit]
      invokesdo_get_date
      (public member function)[edit]
      invokesdo_get_weekday
      (public member function)[edit]
      invokesdo_get_monthname
      (public member function)[edit]
      invokesdo_get_year
      (public member function)[edit]
      (C++11)
      invokesdo_get
      (public member function)[edit]

      [edit]Protected member functions

      [virtual]
      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 fromstd::time_base

      Nested types

      Type Definition
      dateorder date order enumeration type, defining the valuesno_order,dmy,mdy,ymd, andydm

      [edit]Example

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

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

      Possible output:

      Sun Feb 18 23:12:34 2011

      [edit]See also

      formats contents ofstd::tm for output as character sequence
      (class template)[edit]
      (C++11)
      parses a date/time value of specified format
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/time_get&oldid=177993"

      [8]ページ先頭

      ©2009-2025 Movatter.jp