Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      mktime

      From cppreference.com
      <c‎ |chrono
       
       
      Date and time utilities
      Functions
      Time manipulation
      Format conversions
      (deprecated in C23)(C11)
      (deprecated in C23)(C11)
      mktime
      Constants
      Types
       
      Defined in header<time.h>
      time_t mktime(structtm* arg);

      Renormalizes local calendar time expressed as astruct tm object and also converts it to time since epoch as atime_t object.arg->tm_wday andarg->tm_yday are ignored. The values inarg are not checked for being out of range.

      A negative value ofarg->tm_isdst causesmktime to attempt to determine if Daylight Saving Time was in effect in the specified time.

      If the conversion totime_t is successful, thearg object is modified. All fields ofarg are updated to fit their proper ranges.arg->tm_wday andarg->tm_yday are recalculated using information available in other fields.

      Contents

      [edit]Parameters

      arg - pointer to atm object specifying local calendar time to convert

      [edit]Return value

      The time since epoch as atime_t object on success, or-1 ifarg cannot be represented as atime_t object (POSIX also requiresEOVERFLOW to be stored inerrno in this case).

      [edit]Notes

      If thestructtm object was obtained from POSIXstrptime or equivalent function, the value oftm_isdst is indeterminate, and needs to be set explicitly before callingmktime.

      [edit]Example

      Run this code
      #define _POSIX_C_SOURCE 200112L // for setenv on gcc#include <stdio.h>#include <stdlib.h>#include <time.h> int main(void){    setenv("TZ","/usr/share/zoneinfo/America/New_York",1);// POSIX-specific structtmtm=*localtime(&(time_t){time(NULL)});printf("Today is           %s",asctime(&tm));printf("(DST is %s)\n",tm.tm_isdst?"in effect":"not in effect");tm.tm_mon-=100;// tm_mon is now outside its normal range    mktime(&tm);// tm_isdst is not set to -1; today's DST status is usedprintf("100 months ago was %s",asctime(&tm));printf("(DST was %s)\n",tm.tm_isdst?"in effect":"not in effect");}

      Possible output:

      Today is           Fri Apr 22 11:53:36 2016(DST is in effect)100 months ago was Sat Dec 22 10:53:36 2007(DST was not in effect)

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.27.2.3 The mktime function (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.27.2.3 The mktime function (p: 285-286)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.27.2.3 The mktime function (p: 390-391)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.23.2.3 The mktime function (p: 340-341)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 4.12.2.3 The mktime function

      [edit]See also

      converts time since epoch to calendar time expressed as local time
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/chrono/mktime&oldid=183117"

      [8]ページ先頭

      ©2009-2025 Movatter.jp