std::timespec_get
Defined in header <ctime> | | |
|---|---|---|
int timespec_get( std::timespec* ts, int base) | | (since C++17) |
#define TIME_UTC /* implementation-defined */ | | (since C++17) |
1%29修改std::timespec对象所指向的ts在时间基中保存当前日历时间base...
2%29扩展到适合用作base争论std::timespec_get
其他宏常量以TIME_可以由实现提供以指示额外的时间基础。
如果base是TIME_UTC然后。
ts->tv_sec设置为自实现定义的时代以来的秒数,截断为整值。
ts->tv_nsec成员设置为纳秒的整数,舍入到系统时钟的分辨率。
参数
ts | - | pointer to an object of type std::timespec |
|---|---|---|
base | - | TIME_UTC or another nonzero integer value indicating the time base |
返回值
价值base如果成功,否则为零。
注记
POSIX函数钟[医]获取时间%28 CLOCK[医]实时,ts%29也可用于填充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二次
另见
timespec (since C++17) | time in seconds and nanoseconds (struct) |
|---|---|
time | returns the current time of the system as time since epoch (function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

