Mktime is used to convert year, month, day, hour, minute, second to second.

Source: Internet
Author: User

/* Converts Gregorian date to seconds since 00:00:00.
* Assumes input in Normal Date Format, I. e. 23:59:59
* => Year = 1980, MON = 12, Day = 31, hour = 23, min = 59, SEC = 59.
*
* [For the Julian Calendar (which was used in Russia before 1917,
* Britain & colonies before 1752, anywhere else before 1582,
* And is still in use by some communities) leave out
*-Year/100 + year/400 terms, and add 10.]
*
* This algorithm was first published by Gauss (I think ).
*
* Warning: this function will overflow on 2106-02-07 06:28:16 on
* Machines where long is 32-bit! (However, as time_t is signed, we
* Will already get problems at other places on 2038-01-19 03:14:08)
*/
Unsigned long
Mktime (const unsigned int year0, const unsigned int mon0,
Const unsigned int day, const unsigned int hour,
Const unsigned int min, const unsigned int Sec)
{
Unsigned int MON = mon0, year = year0;

/* 1 .. 12-> 11, 12, 1 .. 10 */
If (0> = (INT) (Mon-= 2 )){
Mon + = 12;/* puts Feb last since it has Leap Day */
Year-= 1;
}

Return (unsigned long)
(Year/4-year/100 + year/400 + 367 * Mon/12 + day) +
Year x 365-719499
) * 24 + hour/* now have hours */
) * 60 + min/* now have minutes */
) * 60 + sec;/* finally seconds */
}

Compare the two time ranges.

Time1 = mktime (Y1, M1, D1, H1, M1, S1 );

Time2 = mktime (Y2, M2, D2, H2, M2, S2 );

Interval = time1-time2

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.