C语言获取编译时间
void Get_Compile_Date_Base(uint8_t *Year, uint8_t *Month, uint8_t *Day)
{
const char *pMonth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const char Date[12] = __DATE__;//取编译时间
uint8_t i;
for(i = 0; i < 12; i++)if(memcmp(Date, pMonth[i], 3) == 0)*Month = i + 1, i = 12;
*Year = (uint8_t)atoi(Date + 9); //Date[9]为2位年份,Date[7]为完整年份
*Day = (uint8_t)atoi(Date + 4);
}
char g_date_buf[10];
char* Get_Compile_Date(void)
{
uint8_t Year, Month, Day;
Get_Compile_Date_Base(&Year, &Month, &Day);//取编译时间
sprintf(g_date_buf, "%02d%02d%02d", Year, Month, Day);//任意格式化
return g_date_buf;
}