struct timespec;
(since C11)Structure holding an interval broken down into seconds and nanoseconds.
[edit] Member objects Member Description time_ttv_sec
whole seconds (valid values are >= â0â) /* see below */ tv_nsec
nanoseconds (valid values are [
â0â,
999999999]
)
The type of tv_nsec
is long.
The type of tv_nsec
is an implementation-defined signed integer type that can represent integers in [
â0â,
999999999]
.
The declaration order of tv_sec
and tv_nsec
is unspecified. Implementation may add other members to struct timespec.
The type of tv_nsec
is long long on some platforms, which is conforming only since C23.
#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 UTC Raw timespec.tv_sec: 1712241917 Raw timespec.tv_nsec: 885909786[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4