timespec_get, _timespec32_get, _timespec64_get

基于指定时间基准,将第一个参数指向的间隔设置为当前日历时间。

语法

int timespec_get(
    struct timespec* const time_spec,
    int const base
);
int _timespec32_get(
    struct _timespec32* const time_spec,
    int const base
);
int _timespec64_get(
    struct _timespec64* const time_spec,
    int const base
);

参数

time_spec
设置为自时期开始以来的时间(以秒和纳秒为单位)的结构的指针。

base
一个特定于实现的非零值,指定时间基准。

返回值

如果成功,则值为 base ,否则它返回零。

备注

timespec_get 函数设置 time_spec 参数指向的结构中的当前时间。 此结构的所有版本都具有两个成员,即 tv_sectv_nsectv_sec 值设置为自 tv_nsec 指定的时期开始以来的整秒数, base设置为开始以来的整纳秒数(按系统时钟分辨率进行舍入)。

Microsoft 专用

这些函数仅支持 TIME_UTC 作为 base 值。 TIME_UTCtime_spec 值设置为自时期开始(协调世界时 (UTC) 的 1970 年 1 月 1 日午夜)以来的秒数和纳秒数。 在 _timespec32中, tv_sec__time32_t 值。 在 _timespec64中, tv_sec__time64_t 值。 在 timespec中, tv_sectime_t 类型,其长度为 32 位或 64 位,具体取决于是否定义预处理器宏 _USE_32BIT_TIME_T。 timespec_get 函数是内联函数,如果定义了 _USE_32BIT_TIME_T,将调用 _timespec32_get;否则调用 _timespec64_get

End Microsoft Specific

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

例程 必需的标头
timespec_get, _timespec32_get, _timespec64_get C: <time.h>、C++: <ctime> 或 <time.h>

有关兼容性的详细信息,请参阅 兼容性

另请参阅

工时管理
asctime_wasctime
asctime_s_wasctime_s
_ftime_ftime32_ftime64
gmtime_gmtime32_gmtime64
gmtime_s_gmtime32_s_gmtime64_s
localtime_localtime32_localtime64
localtime_s_localtime32_s_localtime64_s
time_time32_time64
_utime_utime32_utime64_wutime_wutime32_wutime64