C + + mktime ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.