日期时间问题
- C/C++ code
#include <iostream>#include <time.h>using namespace std;int main(){ struct tm dt; dt.tm_year=1970; dt.tm_mon=1; dt.tm_mday=2; dt.tm_hour=0; dt.tm_min=0; dt.tm_sec=0; time_t t=mktime(&dt); cout<<(unsigned long)t<<endl;}程序是在linux下跑的,结果应该是86400啊,为什么是一个巨大的数,请教
[解决办法]
mktime(timeptr)用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的UTC时间所经过的秒数。
所以数据很大!
[解决办法]
timeptr Field Value
tm_hour Hours since midnight (0 23)
tm_isdst Positive if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative if status of daylight saving time is unknown. The C run-time library assumes the United States’s rules for implementing the calculation of Daylight Saving Time (DST).
tm_mday Day of month (1 31)
tm_min Minutes after hour (0 59)
tm_mon Month (0 11; January = 0)
tm_sec Seconds after minute (0 59)
tm_wday Day of week (0 6; Sunday = 0)
tm_yday Day of year (0 365; January 1 = 0)
tm_year Year (current year minus 1900)