localtime_s函数
概要:
#define __STDC_WANT_LIB_EXT1__ 1 #include <time.h> struct tm *localtime_s(const time_t * restrict timer, struct tm * restrict result);
描述:
该函数将参数timer指向的日历时间转换为本地时间表示的分解时间(broken-down time),并将转换结果存储在参数result指向的结构中。
运行约束:
参数timer和参数result不能是空指针。
如果存在运行约束冲突,函数不会尝试转换时间。
参数:
const time_t * restrict timer
指向time_t类型对象的指针。
struct tm * restrict result
指向struct tm类型对象的指针。
返回值:
如果指定时间不能转换成本地时间或者存在运行约束冲突,函数返回空指针;否则函数返回result。
范例:
|
|
输出:
Beijing Time: Wed Jun 22 09:21:38 2022
注:使用Visual Studio编译。
localtime_s函数在Visual Studio中的声明与ISO/IEC 9899:2018标准有差异,Visual Studio中声明如下:
errno_t localtime_s( struct tm *result, const time_t *timer);
差异主要表现在两个方面:
1、返回值不同,Visual Studio中返回类型是errno_t类型;ISO/IEC 9899:2018标准返回的是struct tm类型指针。
2、参数的先后顺序两者正好相反。
相关内容:
localtime | 将time_t类型时间转换为本地时间表示的struct tm类型时间的函数。 |