基于指定时间基准,将第一个参数指向的间隔设置为当前日历时间。
语法
int timespec_get( // See note in remarks section about linkage
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_sec 和 tv_nsec。
tv_sec 值设置为自 tv_nsec 指定的时期开始以来的整秒数, base设置为开始以来的整纳秒数(按系统时钟分辨率进行舍入)。
Microsoft 专用
这些函数仅支持 TIME_UTC 作为 base 值。
TIME_UTC 将 time_spec 值设置为自时期开始(协调世界时 (UTC) 的 1970 年 1 月 1 日午夜)以来的秒数和纳秒数。 在 _timespec32中, tv_sec 是 __time32_t 值。 在 _timespec64中, tv_sec 是 __time64_t 值。 在 timespec中, tv_sec 是 time_t 类型,其长度为 32 位或 64 位,具体取决于是否定义预处理器宏 _USE_32BIT_TIME_T。
timespec_get 函数是内联函数,如果定义了 _timespec32_get,将调用 _USE_32BIT_TIME_T;否则调用 _timespec64_get。
结束Microsoft特定
默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。
注释
使用 Windows SDK 版本 10.0.26100.6901 和 Visual Studio 2026 或更高版本时, timespec_get 不再 static inline (内部链接)。
inline 而是(外部链接)。
若要返回到以前的行为, #define _STATIC_INLINE_UCRT_FUNCTIONS=1 请先包括任何 CRT 标头。 默认情况下,_STATIC_INLINE_UCRT_FUNCTIONS 设置为 0。
此更改增加了与 C++ 标准的 UCRT 一致性,并提高了与C++模块的兼容性。
要求
| 例程 | 必需的标头 |
|---|---|
| .- . | C: <time.h>、C++: <ctime> 或 <time.h> |
有关兼容性的详细信息,请参阅 兼容性。
另请参阅
工时管理
%>
%>
.- .
.- .
.- .
.- .
.- .
.- .
_utime, _utime32, _utime64, _wutime, _wutime32, _wutime64