定义于头文件
<ctime>
|
||
int timespec_get( std::timespec* ts, int base)
|
(C++17 起) | |
#define TIME_UTC /* implementation-defined */
|
(C++17 起) | |
ts
所指向的 std::timespec 对象,以保有时间基底 base
中的当前日历时间。std::timespec_get
的 base
参数的值。实现可提供其他以 TIME_
起始的宏常量,以指示另外的时间基底。
若 base
为 TIME_UTC
,则
ts->tv_sec
被设为从实现定义的纪元开始的秒数,截断到整数值
ts->tv_nsec
成员被设为纳秒的整数,取整到系统时钟的分辨率
目录 |
ts | - | 指向 std::timespec 类型对象的指针 |
base | - | TIME_UTC 或另一指示时间基底的非零整数值
|
若成功则为 base
的值,否则为零。
POSIX 函数 clock_gettime(CLOCK_REALTIME, ts) 亦可用于将从纪元开始的时间植入 std::timespec
。
#include <cstdio> #include <ctime> int main() { std::timespec ts; std::timespec_get(&ts, TIME_UTC); char buff[100]; std::strftime(buff, sizeof buff, "%D %T", std::gmtime(&ts.tv_sec)); std::printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec); }
可能的输出:
Current time: 06/24/16 20:07:42.949494132 UTC
(C++17 起)
|
以秒和纳秒表示的时间 (结构体) |
将系统当前时间作为纪元起时间返回 (函数) |
|
timespec_get的 C 文档
|