timespec_getres
来自cppreference.com
| 在标头 <time.h> 定义
|
||
| |
(C23 起) | |
若 ts 为非空且 timespec_get 支持 base ,则修改 *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) |
返回基于给定时间基底的日历时间 (函数) |
| 返回纪元开始经过的当前系统日历时间 (函数) |