Defined in header <time.h> | ||
|---|---|---|
int timespec_get( struct timespec *ts, int base) | (since C11) | |
#define TIME_UTC /* implementation-defined */ | (since C11) |
timespec object pointed to by ts to hold the current calendar time in the time base base.base argument of timespec_get
Other macro constants beginning with TIME_ may be provided by the implementation to indicate additional time bases.
If base is TIME_UTC, then.
| ts | - | pointer to an object of type struct timespec |
| base | - | TIME_UTC or another nonzero integer value indicating the time base |
The value of base if successful, zero otherwise.
The POSIX function clock_gettime(CLOCK_REALTIME, ts) may also be used to populate a timespec with the time since the Epoch.
#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);
}Output:
Current time: 02/18/15 14:34:03.048508855 UTC
|
(since C11) | time in seconds and nanoseconds (struct) |
| returns the current calendar time of the system as time since epoch (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/chrono/timespec_get