Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      timespec

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

      Structure holding an interval broken down into seconds and nanoseconds.

      Contents

      [edit]Member objects

      Member Description
      time_ttv_sec whole seconds (valid values are >=0)
      /* see below */tv_nsec nanoseconds (valid values are[0999999999])

      The type oftv_nsec islong.

      (until C23)

      The type oftv_nsec is an implementation-defined signed integer type that can represent integers in[0999999999].

      (since C23)

      The declaration order oftv_sec andtv_nsec is unspecified. Implementation may add other members tostruct timespec.

      [edit]Notes

      The type oftv_nsec islonglong on some platforms, which is conforming only since C23.

      [edit]Example

      Run this code
      #include <stdint.h>#include <stdio.h>#include <time.h> int main(void){struct timespec ts;    timespec_get(&ts, TIME_UTC);char buff[100];strftime(buff,sizeof buff,"%D %T",gmtime(&ts.tv_sec));printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec);printf("Raw timespec.tv_sec: %jd\n",(intmax_t)ts.tv_sec);printf("Raw timespec.tv_nsec: %09ld\n", ts.tv_nsec);}

      Possible output:

      Current time: 04/04/24 14:45:17.885909786 UTCRaw timespec.tv_sec: 1712241917Raw timespec.tv_nsec: 885909786

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.27.1/3 Components of time (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.27.1/3 Components of time (p: 284)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.27.1/3 Components of time (p: 388)

      [edit]See also

      returns the calendar time in seconds and nanoseconds based on a given time base
      (function)[edit]
      calendar time type
      (struct)[edit]
      C++ documentation fortimespec
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/chrono/timespec&oldid=180251"

      [8]ページ先頭

      ©2009-2025 Movatter.jp