首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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_可以由实现提供以指示额外的时间基础。

如果baseTIME_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从那个时代开始。

二次

代码语言:javascript
复制
#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);
}

二次

可能的产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com