关于localtime_r的问题!

碎方脸 2009-03-14 11:44:21
我写了一个程序,是用localtime_r得到时间:
#include <stdio.h>
#include <time.h>

int main()
{
time_t t;
struct tm tmTime;
localtime_r(&t, &tmTime);
printf("Date:%d\n",tmTime.tm_mday);
printf("Month:%d\n",tmTime.tm_mon);
printf("Year:%d\n",tmTime.tm_year);
printf("Hour:%d\n",tmTime.tm_hour);
printf("Min:%d\n",tmTime.tm_min);
printf("Sec:%d\n",tmTime.tm_sec);
printf("gmtoff:%d\n",tmTime.tm_gmtoff);
return 0;
}
但是为什么输出和系统时间不一致呢?
[root@localhost abc]# ./abc
Date:18
Month:3
Year:70
Hour:5
Min:36
Sec:48
gmtoff:-18000
[root@localhost abc]# date
Sun Mar 1 00:07:15 EST 2009
...全文
2175 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lemontel 2009-03-15
  • 打赏
  • 举报
回复
t没赋值。

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧