timespec_getres
來自 cppreference.com
定義於標頭檔案 <time.h> |
||
int timespec_getres( struct timespec *ts, int base ); |
(自 C23 起) | |
如果 ts
非空且 base
受 timespec_get 支援,則修改 *ts 以儲存 timespec_get 為 base
提供的時間解析度。對於每個受支援的 base
,在同一程式執行期間對 timespec_getres
的多次呼叫會產生相同的結果。
目錄 |
[編輯] 引數
ts | - | 指向 struct timespec 型別物件的指標 |
base | - | TIME_UTC 或其他非零整數值,表示時間基準 |
[編輯] 返回值
如果 base
受支援,則返回 base
的值,否則返回零。
[編輯] 注意
POSIX 函式 clock_getres(clock_id, ts)
也可用於用 clock_id
標識的時間解析度填充 timespec。
[編輯] 示例
執行此程式碼
#include <stdio.h> #include <time.h> int main(void) { char buff[128]; struct timespec ts; const int res = timespec_getres(&ts, TIME_UTC); if (res == TIME_UTC) { struct tm timer; strftime(buff, sizeof buff, "%D %T", gmtime_r(&ts.tv_sec, &timer)); printf("Time resolution info: %s.%09ld UTC\n", buff, ts.tv_nsec); } else { printf("TIME_UTC base is not supported."); } }
可能的輸出
Time resolution info: 01/01/70 00:00:00.000000001 UTC
[編輯] 另請參閱
(C11) |
秒和納秒時間 (結構體) |
(C11) |
根據給定時間基準返回以秒和納秒錶示的日曆時間 (函式) |
返回系統當前日曆時間,自紀元起的時間 (函式) |