/*******************************************************************
* > File Name: 05-ymd.c
* > Author: fly
* > Mail: XXXXXXXX@icode.com
* > Create Time: Thu Sep 7 16:43:30 2017
******************************************************************/

#include <stdio.h>

// Retrieve year info
#define OS_YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
+ (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))

// Retrieve month info
#define OS_MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
: __DATE__ [2] == 'b' ? 2 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
: __DATE__ [2] == 'y' ? 5 \
: __DATE__ [2] == 'l' ? 7 \
: __DATE__ [2] == 'g' ? 8 \
: __DATE__ [2] == 'p' ? 9 \
: __DATE__ [2] == 't' ? 10 \
: __DATE__ [2] == 'v' ? 11 : 12)

// Retrieve day info
#define OS_DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
+ (__DATE__ [5] - '0'))

// Retrieve hour info
#define OS_HOUR ((__TIME__ [0] - '0') * 10 + (__TIME__ [1] - '0'))

// Retrieve minute info
#define OS_MINUTE ((__TIME__ [3] - '0') * 10 + (__TIME__ [4] - '0'))

// Retrieve second info
#define OS_SECOND ((__TIME__ [6] - '0') * 10 + (__TIME__ [7] - '0'))

static char time_str[32]; //= "YYYYMMDDHHMMSSres";

char *get_build_time(void)
{
#if (1)
sprintf(time_str,"%02d%02d%02d", OS_YEAR%100, OS_MONTH, OS_DAY);
#else
sprintf(time_str, "%04d%02d%02d%02d%02d%02d", OS_YEAR, OS_MONTH, OS_DAY, OS_HOUR, OS_MINUTE, OS_SECOND);
#endif

return time_str;
}

int main(int argc, char* argv[])
{
printf("build time :%s\tbuild date :%s\n", __TIME__, __DATE__);
printf("%s\n", get_build_time());

return 0;
}