?
This document uses PHP Chinese website manual Release
在頭文件<time.h>中定義 | ||
---|---|---|
int timespec_get(struct timespec * ts,int base) | (自C11以來) | |
#define TIME_UTC / *實(shí)現(xiàn)定義的* / | (自C11以來) |
1)修改timespec
指向的對(duì)象以ts
在時(shí)基中保存當(dāng)前日歷時(shí)間base
。
2)擴(kuò)展為適合用作base
參數(shù)的值timespec_get
其他的宏常量TIME_
可以由實(shí)現(xiàn)提供,以指示附加的時(shí)基。
如果base
是TIME_UTC
,那么。
ts-> tv_sec被設(shè)置為自實(shí)現(xiàn)定義時(shí)期以來的秒數(shù),被截?cái)酁檎麄€(gè)值
ts-> tv_nsec成員設(shè)置為納秒的整數(shù)倍數(shù),取整為系統(tǒng)時(shí)鐘的分辨率
TS | - | 指向struct timespec類型的對(duì)象的指針 |
---|---|---|
基礎(chǔ) | - | TIME_UTC或指示時(shí)基的另一個(gè)非零整數(shù)值 |
base
成功的價(jià)值,否則為零。
POSIX函數(shù)clock_gettime(CLOCK_REALTIME,ts)也可以用來填充timespec
自Epoch以來的時(shí)間。
#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);}
輸出:
Current time: 02/18/15 14:34:03.048508855 UTC
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.27.2.5 timespec_get函數(shù)(p:390)