关于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