Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::time_put

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

         class CharT,
         class OutputIt=std::ostreambuf_iterator<CharT>

      >class time_put;

      Class templatestd::time_put encapsulates date and time formatting rules. The I/O manipulatorstd::put_time uses thestd::time_put facet of the I/O stream's locale to generate text representation of anstd::tm object.

      std-time put-inheritance.svg

      If astd::time_put specialization is not guaranteed to be provided by the standard library (see below), the behaviors of itsput() anddo_put() 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_put<char> creates narrow string representations of date and time
      std::time_put<wchar_t> creates 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_typeOutputIt

      [edit]Data members

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

      [edit]Member functions

      constructs a newtime_put facet
      (public member function)[edit]
      destructs atime_put facet
      (protected member function)[edit]
      invokesdo_put
      (public member function)[edit]

      [edit]Protected member functions

      [virtual]
      formats date/time and writes to output stream
      (virtual protected member function)[edit]

      [edit]Example

      Run this code
      #include <codecvt>#include <ctime>#include <iomanip>#include <iostream> int main(){std::time_t t=std::time(nullptr);std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf());std::wostream out(&conv);    out.imbue(std::locale("ja_JP.utf8")); // this I/O manipulator std::put_time uses std::time_put<wchar_t>    out<<std::put_time(std::localtime(&t), L"%A %c")<<'\n';}

      Output:

      水曜日 2011年11月09日 12時32分05秒

      [edit]See also

      represents the system-suppliedstd::time_put for the named locale
      (class template)[edit]
      parses time/date values from an input character sequence intostd::tm
      (class template)[edit]
      (C++11)
      formats and outputs a date/time value according to the specified format
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/time_put&oldid=179458"

      [8]ページ先頭

      ©2009-2025 Movatter.jp