Mktime C Language Implementation

Source: Internet
Author: User

Code:

#include <time.h>enum time_def{sec = 1, min = sec *, HOUR = MIN *, day = HOUR *, year = day * 365,};time_t time_difference = 8 * hour;static time_t mon_yday[2][12] ={{0, 31, 59, 90, 120, 151, 181, 212, 243, 273  , 304, 334}, {0,31, 182, 213, 244, 274, 305, 335},};int Leap (int year) {if (year% 400 = = 0) | | (year% 4 = = 0 && Year% 100! = 0))    {return 1; } return 0;}    Long Long Get_day (int year) {year = year-1;    int leap_year_num = YEAR/4-year/100 + year/400;    Long Long tol_day = year * 365 + leap_year_num; return tol_day;}    time_t mymktime (int year,int mon,int day,int hour,int min,int sec) {Long long tol_day = 0;    Year + = 1900;    Tol_day = Get_day (year)-Get_day (1970);    Tol_day + = Mon_yday[leap (year)][mon];    Tol_day + = day-1;    Long long ret = 0;    RET + = Tol_day * DAY;    RET + = hour * HOUR;    RET + = min * min;    RET + = sec * sec; return ret-time_difference;} time_t myMktime (tm* mk) {if (!MK) {return-1; } if (! (     mk->tm_sec>= 0 && mk->tm_sec <=)) {return-1; } if (! (     mk->tm_min>= 0 && mk->tm_min <=)) {return-1; } if (! (     mk->tm_hour>= 0 && mk->tm_hour <=)) {return-1; } if (! (     mk->tm_mday>= 1 && mk->tm_hour <=)) {return-1; } if (! (     mk->tm_mon>= 0 && Mk->tm_mon <=)) {return-1; } if (! (     mk->tm_year>=) {return-1;  } return Mymktime (MK-&GT;TM_YEAR,MK-&GT;TM_MON,MK-&GT;TM_MDAY,MK-&GT;TM_HOUR,MK-&GT;TM_MIN,MK-&GT;TM_SEC);}

  

Mktime C Language Implementation

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.