Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      timespec_getres

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

      Ifts is non-null andbase is supported bytimespec_get, modifies*ts to hold the resolution of time provided bytimespec_get forbase. For each supportedbase, multiple calls totimespec_getres during the same program execution have identical results.

      Contents

      [edit]Parameters

      ts - pointer to an object of typestruct timespec
      base -TIME_UTC or another nonzero integer value indicating the time base

      [edit]Return value

      The value ofbase ifbase is supported, zero otherwise.

      [edit]Notes

      The POSIX functionclock_getres(clock_id, ts) may also be used to populate atimespec with the resolution of time identified byclock_id.

      [edit]Example

      Run this code
      #include <stdio.h>#include <time.h> int main(void){char buff[128];struct timespec ts;constint res= timespec_getres(&ts, TIME_UTC);if(res== TIME_UTC){structtm timer;strftime(buff,sizeof buff,"%D %T", gmtime_r(&ts.tv_sec,&timer));printf("Time resolution info: %s.%09ld UTC\n", buff, ts.tv_nsec);}else{printf("TIME_UTC base is not supported.");}}

      Possible output:

      Time resolution info: 01/01/70 00:00:00.000000001 UTC

      [edit]See also

      time in seconds and nanoseconds
      (struct)[edit]
      returns the calendar time in seconds and nanoseconds based on a given time base
      (function)[edit]
      returns the current calendar time of the system as time since epoch
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/chrono/timespec_getres&oldid=125006"

      [8]ページ先頭

      ©2009-2026 Movatter.jp