加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 21:03:29 所属栏目:Windows 来源:网络整理
导读:通过对文件编译时间的获得,可以用来定义App发布时的版本. 以下是C++,MFC的示例: CString g_strToolDate;CString g_strCopyRight; void SetCompileDateTime(){ const char *szEnglishMonth[ 12 ]= { "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" ,

通过对文件编译时间的获得,可以用来定义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下获取也差不多.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读