Date and time the system was obtained at compile time

Source: Internet
Author: User

__date__ and __time__ are the 2 more useful macros built into C that can return the date and time that the program was compiled. is useful for version control. is itself a struct tm* type and can be converted using the strftime () function

printf ("%s--%s", __time__,__date__);

Static time_t Getdatefrommacro (char const *time) {
Char s_month[5];
Int month, day, year;
struct TM T = {0};
static const char month_names[] = "Janfebmaraprmayjunjulaugsepoctnovdec";

SSCANF (Time, "%s%d%d", S_month, &day, &year);

Month = (Strstr (month_names, S_month)-month_names)/3;

T.tm_mon = month;
T.tm_mday = day;
T.tm_year = year-1900;
T.TM_ISDST =-1;

Return Mktime (&t);
}
After converting to time_t, it is already basically the main road. time_t included in the time.h.

#ifndef __time_t

#define __time_t

typedef long time_t;
/* To save seconds from January 1, 1970 0:0 0 seconds to the present moment!
Use the time () function to get */

#endif


#if ((__date__[0] = = ' J ') && (__date__[1] = = ' a ') && (__date__[2] = = ' n '))
#define MONTHNUM 1
#elif ((__date__[0] = = ' F ') && (__date__[1] = = ' E ') && (__date__[2] = = ' B '))
#define MONTHNUM 2
#endif
#if ((__date__[0] = = ' M ') && (__date__[1] = = ' a ') && (__date__[2] = = ' R '))
#define MONTHNUM 3
#elif ((__date__[0] = = ' A ') && (__date__[1] = = ' P ') && (__date__[2] = = ' R '))
#define MONTHNUM 4
#endif
#if ((__date__[0] = = ' M ') && (__date__[1] = = ' a ') && (__date__[2] = = ' Y '))
#define MONTHNUM 5
#elif ((__date__[0] = = ' J ') && (__date__[1] = = ' u ') && (__date__[2] = = ' n '))
#define MONTHNUM 6
#endif
#if ((__date__[0] = = ' J ') && (__date__[1] = = ' u ') && (__date__[2] = = ' l '))
#define MONTHNUM 7
#elif ((__date__[0] = = ' A ') && (__date__[1] = = ' u ') && (__date__[2] = = ' g '))
#define MONTHNUM 8
#endif
#if ((__date__[0] = = ' S ') && (__date__[1] = = ' E ') && (__date__[2] = = ' P '))
#define MONTHNUM 9
#elif ((__date__[0] = = ' O ') && (__date__[1] = = ' C ') && (__date__[2] = = ' t '))
#define Monthnum 0x10
#endif
#if ((__date__[0] = = ' N ') && (__date__[1] = = ' O ') && (__date__[2] = = ' V '))
#define Monthnum 0x11
#elif ((__date__[0] = = ' D ') && (__date__[1] = = ' E ') && (__date__[2] = = ' C '))
#define Monthnum 0x12
#endif


Const unsigned char version_date[] = {
((__date__[9]-' 0 ') *16) + (__date__[10]-' 0 ')),
Monthnum,
((__date__[4]-' 0 ') *16) + (__date__[5]-' 0 ')),
};


Const unsigned char version_time[] = {
((__time__[0]-' 0 ') *16) + (__time__[1]-' 0 ')),
((__time__[3]-' 0 ') *16) + (__time__[4]-' 0 ')),
((__time__[6]-' 0 ') *16) + (__time__[7]-' 0 ')),
};

Date and time the system was obtained at compile time

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.