<Windows> C/C++获取编译时间

前端之家收集整理的这篇文章主要介绍了<Windows> C/C++获取编译时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

通过对文件编译时间的获得,可以用来定义App发布时的版本.
以下是C++,MFC的示例:

CString g_strToolDate;
CString g_strCopyRight;
void SetCompileDateTime()
{
    const char *szEnglishMonth[12]= {
        "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",};
    char szTmpDate[100]={0}; 
    char szTmpTime[100]={0}; 
    char szMonth[10]={0}; 
    wchar_t szDateTime[250] = {0};
    int iYear,iMonth,iDay;
    int iHour,iMin,iSec;

    //获取编译日期、时间 
    sprintf_s(szTmpDate,"%s",__DATE__); //"Sep 18 2010" 
    sprintf_s(szTmpTime,__TIME__); //"10:59:19" 

    memcpy(szMonth,szTmpDate,3);
    for (int i=0; i < 12; i++) 
    { 
        if (strncmp(szMonth,szEnglishMonth[i],3) == 0) 
        { 
            iMonth=i+1; 
            break; 
        } 
    } 
    memset(szMonth,0,10);
    memcpy(szMonth,szTmpDate+4,2);
    iDay = atoi(szMonth);

    memset(szMonth,szTmpDate+7,4);
    iYear = atoi(szMonth);


    memset(szMonth,szTmpTime,2);
    iHour = atoi(szMonth);

    memset(szMonth,szTmpTime+3,2);
    iMin = atoi(szMonth);


    memset(szMonth,szTmpTime+6,2);
    iSec = atoi(szMonth);


    wsprintf(szDateTime,TEXT("App Build@%4d-%02d-%02d_%02d:%02d:%02d"),iYear,iDay,iHour,iSec); 

    TRACE(TEXT("%s"),szDateTime);
    TRACE("\n");
    g_strToolDate = szDateTime;


    sprintf_s(szTmpDate,"Lulixue Copyright(C) %d",iYear);
    g_strCopyRight = szTmpDate;
}

在About窗口提示:

Linux下获取也差不多.

原文链接:https://www.f2er.com/windows/372657.html

猜你在找的Windows相关文章