The header declares the structure tm, which includes at least the following members:

int tm_sec seconds [0,61]
int tm_min minutes [0,59]
int tm_hour hour [0,23]
int tm_mday day of month [1,31]
int tm_mon month of year [0,11]
int tm_year years since 1900
int tm_wday day of week [0,6] (Sunday = 0)
int tm_yday day of year [0,365]
int tm_isdst daylight savings flag

The value of tm_isdst is positive if Daylight Saving Time is in effect, 0 if Daylight Saving Time is not in effect, and negative if the information is not available.



#include
time_t tm;
struct tm ptime;

ptime.tm_sec = 0;
ptime.tm_min = 0;
ptime.tm_hour = 0;
ptime.tm_mday = 1;
ptime.tm_mon = 12 - 1;
ptime.tm_year = 2007 - 1900;

tm=mktime(&ptime);
stime(&tm);

time_t mktime(struct tm *tp);
转换tm成为time_t格式,使用本地时间。

tme_t timegm(strut tm *tp);  or  
tme_t timelocal(strut tm *tp); 
转换tm成为time_t格式,使用UTC时间。

創作者介紹

邱小新の工作筆記

台南小新 發表在 痞客邦 PIXNET 留言(0) 人氣()