Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      time

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

      Returns the current calendar time encoded as atime_t object, and also stores it in thetime_t object pointed to byarg (unlessarg is a null pointer)

      Contents

      [edit]Parameters

      arg - pointer to atime_t object where the time will be stored, or a null pointer

      [edit]Return value

      Current calendar time encoded astime_t object on success,(time_t)(-1) on error. Ifarg is not a null pointer, the return value is also stored in the object pointed to byarg.

      [edit]Notes

      The encoding of calendar time intime_t is unspecified, but most systems conform toPOSIX specification and return a value of integral type holding the number of seconds sincethe Epoch. Implementations in whichtime_t is a 32-bit signed integer (many historical implementations) fail in the year2038.

      [edit]Example

      Run this code
      #include <stdint.h>#include <stdio.h>#include <time.h> int main(void){time_t result= time(NULL);if(result!=(time_t)(-1))printf("The current time is %s(%jd seconds since the Epoch)\n",asctime(gmtime(&result)),(intmax_t)result);}

      Possible output:

      The current time is Fri Apr 24 15:05:25 2015(1429887925 seconds since the Epoch)

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.27.2.4 The time function (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.27.2.4 The time function (p: 286)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.27.2.4 The time function (p: 391)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.23.2.4 The time function (p: 341)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 4.12.2.4 The time function

      [edit]See also

      converts time since epoch to calendar time expressed as local time
      (function)[edit]
      converts time since epoch to calendar time expressed as Coordinated Universal Time (UTC)
      (function)[edit]
      returns the calendar time in seconds and nanoseconds based on a given time base
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/chrono/time&oldid=180264"

      [8]ページ先頭

      ©2009-2025 Movatter.jp