localtime_r、localtime_s 和 localtime 都是用于将 time_t 转换为本地时间 struct tm 的函数,但它们在线程安全性和跨平台支持上有重要区别:
1. localtime (C标准库)
特点:
- 非线程安全:内部使用静态缓冲区,多次调用会覆盖结果
- 头文件:
<time.h>或<ctime> - 原型:
struct tm* localtime(const time_t* timer);
问题示例:
time_t t1, t2;
time(&t1);
time(&t2);
struct tm* tm1 = localtime(&t1); // 第一次调用
struct tm* t

2288

被折叠的 条评论
为什么被折叠?



