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 (structTM *The TM structure is defined as follows:structTM {intTm_sec;/*seconds – The value interval is [0,59]*/intTm_min;/*min-Value interval is [0,59]*/intTm_hour;/*time-value interval is [0,23]*/intTm_mday;/*date in one months-the range of values is [1,31]*/intTm_mon;/*month (starting from January, 0 for January)-value range is [0,11]*/intTm_year;/*year, whose value is equal to the actual year minus 1900*/intTm_wday;/*Week – The value interval is [0,6], where 0 represents Sunday, 1 represents Monday, and so on*/intTm_yday;/*days starting January 1 of each year – the value interval is [0,365], where 0 represents January 1, 1 is January 2, and so on*/intTM_ISDST;/*Daylight Saving Time identifier, the TM_ISDST is positive. 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. Table header file # include definition function time_t mktime (strcut TM*timeptr); function Description Mktime () is used to convert the TM structure data referred to by the parameter timeptr to the number of seconds elapsed from the UTC time of January 1, 1970 0:0 0 seconds to date. The return value returns the number of seconds elapsed. Example/*time (in seconds) to convert the struct TM to the original number of seconds using localtime () to a struct TM and Mktine ()*/#include #include main () {time_t Timep;strcut TM*P;time (&TIMEP);p rintf ("Time ():%d \ n", TIMEP);p=localtime (&TIMEP); TIMEP=mktime (P);p rintf ("Time ()->localtime ()->mktime ():%d\n", TIMEP);} Execute time ():974943297Time ()->localtime ()->mktime ():974943297
function and usage of mktime function in C language