Today contact Write a calendar program, need to figure out the first day of the month is the days of the week, the use of mktime () This function, feel this function is very useful, share to everyone.
Prototype: time_t mktime (struct TM *)
The TM structure is defined as follows:
struct TM {int tm_sec;/* seconds-the value interval is [0,59] */int tm_min;/*-The value interval is [0,59] */int tm_hour;/* When-the value interval is [0,23] */int Tm_mday ; /* Date in one months-the value interval is [1,31] */int Tm_mon; /* Month (starting from January, 0 for January)-the value interval is [0,11] */int tm_year; /* year, whose value equals the actual year minus 1900 */int Tm_wday; /* Week – The value interval is [0,6], where 0 represents Sunday, 1 for Monday, and so on */int Tm_yday; /* Number of days from January 1 of each year – the value interval is [0,365], where 0 represents January 1, 1 is January 2, and so on */int tm_isdst; /* Daylight Saving time identifier, the TM_ISDST is positive when daylight savings is applied. Without daylight saving time, TM_ISDST is 0 and TM_ISDST () is negative when the situation is not known. */};
We just give the date of the month and minute, and then use Mktime () to be able to get the week of existence in Tm_wday.
Seems to be wrong to write a date will automatically change, such as write a 32 days will be changed to February 1, very powerful.
time_t GPCL:: Systime_to_timet (const systemtime& ST) {struct TM GM = {st.wsecond, St.wminute, St.whour, St.wday, St.wMo Nth-1, st.wyear-1900, St.wdayofweek, 0, 0};return mktime (&GM);}
C + + mktime ()