localtime_r函数
概要:
#include <time.h> struct tm *localtime_r(const time_t *timer, struct tm *buf);
描述:
该函数将参数timer指向的日历时间转换为以本地时间表示的分解时间(broken-down time)。
localtime_r函数和localtime函数功能基本相同,不同之处在于:localtime_r函数将转换结果存入参数buf指向的缓冲区,并返回该指针。localtime_r函数不受数据竞争的影响,除非在多线程执行中时间或者日历发生了改变。
参数:
const time_t *timer
参数为指向const time_t类型对象的指针。
struct tm *buf
参数为指向struct tm类型对象的指针。
返回值:
函数返回指向分解时间的指针;如果指定的时间不能转换为本地时间,函数返回空指针。
范例:
|
|
输出:
Beijing Time: Tue Sep 22 11:35:30 2026
UTC Time: Tue Sep 22 03:35:30 2026
相关内容:
| gmtime_r | 将time_t类型日历时间转换为UTC时间表示的struct tm类型分解时间的函数。 |
| localtime | 将time_t类型日历时间转换为本地时间表示的struct tm类型分解时间的函数。 |
| time_t | 表示日历时间的实数类型。 |
| struct tm | 表示分解时间的结构类型。 |
主要参考资料: