C专家编程-前言
C专家编程-前言中提出的一个有关时间最大值小问题。
在time.h中 time_t是long的typedef形式。long和int在标准C中都为32bits
#include <stdio.h>
#include <time.h>
int main()
{
time_t biggest = 0x7FFFFFFF;
/* ctime() function converts the calendar time time to local
time of the format */
printf("biggest = %s \n",ctime(&biggest));
/* gmtime() function returns the given time in Coordinated
Universal Time
asctime() converts the time in the struct 'ptr' to a
character string of the following format:
day month date hours:minutes:seconds year */
printf("biggest = %s \n", asctime(gmtime(&biggest)));
return 0;
}
输出结果为:
![](http://hiphotos.baidu.com/gylxue/pic/item/97d864f235651722b17ec526.jpg)
ctime()函数把参数转换为当地时间,它跟世界统一时间UTC并不一致,取决于你所在的时区。在中国得到的最大时间就要比标准格林尼治时间多8个小时。
如果你采用的是新西兰的时区,时间又会发生改变,而且新西兰有一部分位于日界线的东面,因此又会产生不同的时间结果。
如果有人觉得对日期编程是小菜一碟,一次动手便可轻松搞定,那么他肯定没有深入研究问题,程序的质量也可想而知。--Peter Van Der Linden
在time.h中 time_t是long的typedef形式。long和int在标准C中都为32bits
#include <stdio.h>
#include <time.h>
int main()
{
time_t biggest = 0x7FFFFFFF;
/* ctime() function converts the calendar time time to local
time of the format */
printf("biggest = %s \n",ctime(&biggest));
/* gmtime() function returns the given time in Coordinated
Universal Time
asctime() converts the time in the struct 'ptr' to a
character string of the following format:
day month date hours:minutes:seconds year */
printf("biggest = %s \n", asctime(gmtime(&biggest)));
return 0;
}
输出结果为:
![](http://hiphotos.baidu.com/gylxue/pic/item/97d864f235651722b17ec526.jpg)
ctime()函数把参数转换为当地时间,它跟世界统一时间UTC并不一致,取决于你所在的时区。在中国得到的最大时间就要比标准格林尼治时间多8个小时。
如果你采用的是新西兰的时区,时间又会发生改变,而且新西兰有一部分位于日界线的东面,因此又会产生不同的时间结果。
如果有人觉得对日期编程是小菜一碟,一次动手便可轻松搞定,那么他肯定没有深入研究问题,程序的质量也可想而知。--Peter Van Der Linden