1 /*
2 int timespec_get(struct timespec * ts,int base);
3 #define TIME_UTC //base指定时间基准,通常设置为TIME_UTC,表示获取UTC时间
4 */
5 #include <stdio.h>
6 #include <time.h>
7
8 int main(void)
9 {
10 struct timespec ts;
11 timespec_get(&ts, TIME_UTC);
12 char buff[100];
13 strftime(buff, sizeof buff, "%D %T", gmtime(&ts.tv_sec));
14 printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec);
15 }
16
10-20
2456
07-28
1357