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) |
基于给定的时间基准,返回以秒和纳秒为单位的日历时间 (函数) |
返回系统当前的日历时间,表示为自 epoch 以来的时间 (函数) |