Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::put_time

      From cppreference.com
      <cpp‎ |io‎ |manip
       
       
       
      Input/output manipulators
      Floating-point formatting
      Integer formatting
      Boolean formatting
      Field width and fill control
      Other formatting
      Whitespace processing
      Output flushing
      Status flags manipulation
      Time and money I/O
      (C++11)
      (C++11)
      (C++11)
      put_time
      (C++11)
      Quoted manipulator
      (C++14)
       
      Defined in header<iomanip>
      template<class CharT>
      /*unspecified*/ put_time(conststd::tm* tmb,const CharT* fmt);
      (since C++11)

      When used in an expressionout<< put_time(tmb, fmt), converts the date and time information from a given calendar timetmb to a character string according toformat stringfmt, as if by callingstd::strftime,std::wcsftime, or analog (depending onCharT), according to thestd::time_put facet of the locale currently imbued in the output streamout.

      Contents

      [edit]Parameters

      tmb - pointer to the calendar time structure as obtained fromstd::localtime orstd::gmtime
      fmt - pointer to a null-terminatedCharT string specifying theformat of conversion

      [edit]Format string

      The format string consists of zero or more conversion specifiers and ordinary characters (except%). All ordinary characters, including the terminating null character, are copied to the output string without modification. Each conversion specification begins with% character, optionally followed byE orO modifier (ignored if unsupported by the locale), followed by the character that determines the behavior of the specifier. The following format specifiers are available:

      Conversion
      specifier
      Explanation Used fields
      % writes literal%. The full conversion specification must be%%.
      n
      (C++11)
      writes newline character
      t
      (C++11)
      writes horizontal tab character
      Year
      Y writesyear as a decimal number, e.g. 2017tm_year
      EY
      (C++11)
      writesyear in the alternative representation, e.g.平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localetm_year
      y writes last 2 digits ofyear as a decimal number (range[00,99])tm_year
      Oy
      (C++11)
      writes last 2 digits ofyear using the alternative numeric system, e.g. 十一 instead of 11 in ja_JP localetm_year
      Ey
      (C++11)
      writesyear as offset from locale's alternative calendar period%EC (locale-dependent)tm_year
      C
      (C++11)
      writes first 2 digits ofyear as a decimal number (range[00,99])tm_year
      EC
      (C++11)
      writes name of thebase year (period) in the locale's alternative representation, e.g. 平成 (Heisei era) in ja_JPtm_year
      G
      (C++11)
      writesISO 8601 week-based year, i.e. the year that contains the specified week.

      In ISO 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

      • Includes January 4
      • Includes first Thursday of the year
      tm_year,tm_wday,tm_yday
      g
      (C++11)
      writes last 2 digits ofISO 8601 week-based year, i.e. the year that contains the specified week (range[00,99]).

      In ISO 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

      • Includes January 4
      • Includes first Thursday of the year
      tm_year,tm_wday,tm_yday
      Month
      b writesabbreviated month name, e.g.Oct (locale dependent)tm_mon
      h
      (C++11)
      synonym ofbtm_mon
      B writesfull month name, e.g.October (locale dependent)tm_mon
      m writesmonth as a decimal number (range[01,12])tm_mon
      Om
      (C++11)
      writesmonth using the alternative numeric system, e.g. 十二 instead of 12 in ja_JP localetm_mon
      Week
      U writesweek of the year as a decimal number (Sunday is the first day of the week) (range[00,53])tm_year,tm_wday,tm_yday
      OU
      (C++11)
      writesweek of the year, as by%U, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
      W writesweek of the year as a decimal number (Monday is the first day of the week) (range[00,53])tm_year,tm_wday,tm_yday
      OW
      (C++11)
      writesweek of the year, as by%W, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
      V
      (C++11)
      writesISO 8601 week of the year (range[01,53]).

      In ISO 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

      • Includes January 4
      • Includes first Thursday of the year
      tm_year,tm_wday,tm_yday
      OV
      (C++11)
      writesweek of the year, as by%V, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
      Day of the year/month
      j writesday of the year as a decimal number (range[001,366])tm_yday
      d writesday of the month as a decimal number (range[01,31])tm_mday
      Od
      (C++11)
      writes zero-basedday of the month using the alternative numeric system, e.g. 二十七 instead of 27 in ja_JP locale

      Single character is preceded by a space.

      tm_mday
      e
      (C++11)
      writesday of the month as a decimal number (range[1,31]).

      Single digit is preceded by a space.

      tm_mday
      Oe
      (C++11)
      writes one-basedday of the month using the alternative numeric system, e.g. 二十七 instead of 27 in ja_JP locale

      Single character is preceded by a space.

      tm_mday
      Day of the week
      a writesabbreviated weekday name, e.g.Fri (locale dependent)tm_wday
      A writesfull weekday name, e.g.Friday (locale dependent)tm_wday
      w writesweekday as a decimal number, where Sunday is0 (range[0-6])tm_wday
      Ow
      (C++11)
      writesweekday, where Sunday is0, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP localetm_wday
      u
      (C++11)
      writesweekday as a decimal number, where Monday is1 (ISO 8601 format) (range[1-7])tm_wday
      Ou
      (C++11)
      writesweekday, where Monday is1, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP localetm_wday
      Hour, minute, second
      H writeshour as a decimal number, 24 hour clock (range[00-23])tm_hour
      OH
      (C++11)
      writeshour from 24-hour clock using the alternative numeric system, e.g. 十八 instead of 18 in ja_JP localetm_hour
      I writeshour as a decimal number, 12 hour clock (range[01,12])tm_hour
      OI
      (C++11)
      writeshour from 12-hour clock using the alternative numeric system, e.g. 六 instead of 06 in ja_JP localetm_hour
      M writesminute as a decimal number (range[00,59])tm_min
      OM
      (C++11)
      writesminute using the alternative numeric system, e.g. 二十五 instead of 25 in ja_JP localetm_min
      S writessecond as a decimal number (range[00,60])tm_sec
      OS
      (C++11)
      writessecond using the alternative numeric system, e.g. 二十四 instead of 24 in ja_JP localetm_sec
      Other
      c writesstandard date and time string, e.g.Sun Oct 17 04:41:13 2010 (locale dependent) all
      Ec
      (C++11)
      writesalternative date and time string, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale all
      x writes localizeddate representation (locale dependent) all
      Ex
      (C++11)
      writesalternative date representation, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale all
      X writes localizedtime representation, e.g. 18:40:20 or 6:40:20 PM (locale dependent) all
      EX
      (C++11)
      writesalternative time representation (locale dependent) all
      D
      (C++11)
      equivalent to"%m/%d/%y"tm_mon,tm_mday,tm_year
      F
      (C++11)
      equivalent to"%Y-%m-%d" (the ISO 8601 date format)tm_mon,tm_mday,tm_year
      r
      (C++11)
      writes localized12-hour clock time (locale dependent)tm_hour,tm_min,tm_sec
      R
      (C++11)
      equivalent to"%H:%M"tm_hour,tm_min
      T
      (C++11)
      equivalent to"%H:%M:%S" (the ISO 8601 time format)tm_hour,tm_min,tm_sec
      p writes localizeda.m. or p.m. (locale dependent)tm_hour
      z
      (C++11)
      writesoffset from UTC in the ISO 8601 format (e.g.-0430), or no characters if the time zone information is not availabletm_isdst
      Z writes locale-dependenttime zone name or abbreviation, or no characters if the time zone information is not availabletm_isdst

      [edit]Return value

      An object of unspecified type such that

      • ifout is an object of typestd::basic_ostream<CharT, Traits>, the expressionout<< put_time(tmb, fmt)
        • has typestd::basic_ostream<CharT, Traits>&
        • has valueout
        • behaves as if it calledf(out, tmb, fmt)

      where the functionf is defined as:

      template<class CharT,class Traits>void f(std::basic_ios<CharT, Traits>& str,conststd::tm* tmb,const CharT* fmt){using Iter=std::ostreambuf_iterator<CharT, Traits>;using TimePut=std::time_put<CharT, Iter>; const TimePut& tp=std::use_facet<TimePut>(str.getloc());const Iter end= tp.put(Iter(str.rdbuf()), str, str.fill(), tmb,        fmt, fmt+ Traits::length(fmt)); if(end.failed())        str.setstate(std::ios_base::badbit);}

      [edit]Example

      Run this code
      #include <ctime>#include <iomanip>#include <iostream> int main(){std::time_t t=std::time(nullptr);std::tm tm=*std::localtime(&t); std::cout.imbue(std::locale("ru_RU.utf8"));std::cout<<"ru_RU: "<< std::put_time(&tm,"%c %Z")<<'\n'; std::cout.imbue(std::locale("ja_JP.utf8"));std::cout<<"ja_JP: "<< std::put_time(&tm,"%c %Z")<<'\n';}

      Possible output:

      ru_RU: Ср. 28 дек. 2011 10:21:16 ESTja_JP: 2011年12月28日 10時21分16秒 EST

      [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]
      converts astd::tm object to custom textual representation
      (function)[edit]
      converts astd::tm object to custom wide string textual representation
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/manip/put_time&oldid=159179"

      [8]ページ先頭

      ©2009-2025 Movatter.jp