Defined in header <time.h> | ||
---|---|---|
struct timespec; | (since C11) |
Structure holding an interval broken down into seconds and nanoseconds.
time_t tv_sec | whole seconds (valid values are >= 0) |
long tv_nsec | nanoseconds (valid values are [0, 999999999]) |
#include <stdio.h> #include <time.h> #include <stdint.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.time_t: %jd\n", (intmax_t)ts.tv_sec); printf("Raw timespec.tv_nsec: %09ld\n", ts.tv_nsec); }
Possible output:
Current time: 11/24/21 03:10:50.408191283 UTC Raw timespec.time_t: 1637723450 Raw timespec.tv_nsec: 408191283
(C11) | returns the calendar time in seconds and nanoseconds based on a given time base (function) |
calendar time type (struct) |
|
C++ documentation for timespec |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/c/chrono/timespec