timespec_getres
来自 cppreference.cn
定义于头文件 <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) |
根据给定时间基准返回以秒和纳秒表示的日历时间 (函数) |
返回系统当前日历时间,自纪元起的时间 (函数) |