1. 程式人生 > >C語言獲取編譯器時間(keil5 MDK)

C語言獲取編譯器時間(keil5 MDK)

static void gettimertohex(const char* p_str,char* pbuf)
{  
  char lenght = strlen(p_str);


if (lenght != 8)
{
return;
}
*pbuf++=(p_str[0]-'0')*10+(p_str[1]-'0');//shi
*pbuf++=(p_str[3]-'0')*10+(p_str[4]-'0');//fen
*pbuf++=(p_str[6]-'0')*10+(p_str[7]-'0');//miao
printf("%d:%d:%d\r\n",pTime[0],pTime[1],pTime[2]);

}

其中p_str可以是__TIME__,__TIME__是C語言自帶的,本文只是將獲取到的內容轉換成HEX格式以便進行其他處理,如果要使用字串則可以直接使用__TIME__,比如printf(“%s”,__TIME__);則可以通過串列埠等輸出當前工程最新編譯時間。