<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > C語言獲取編譯日期時間和系統(tǒng)時間

          C語言獲取編譯日期時間和系統(tǒng)時間

          作者: 時間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
          int GetCompileDateTime(char *szDateTime)
          {
          const intMONTH_PER_YEAR=12;
          const char szEnglishMonth[MONTH_PER_YEAR][4]={ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
          char szTmpDate[40]={0};
          char szTmpTime[20]={0};
          char szMonth[4]={0};
          int iYear,iMonth,iDay,iHour,iMin,iSec;//,,

          //獲取編譯日期、時間
          sprintf(szTmpDate,"%s",__DATE__); //"Sep 18 2010"
          sprintf(szTmpTime,"%s",__TIME__);//"10:59:19"

          sscanf(szTmpDate,"%s %d %d",szMonth,&iDay,&iYear);
          sscanf(szTmpTime,"%d:%d:%d",&iHour,&iMin,&iSec);

          for(int i=0;MONTH_PER_YEAR;i++)
          {
          if(strncmp(szMonth,szEnglishMonth[i],3)==0)
          {
          iMonth=i+1;
          break;
          }
          }

          printf("%d,%d,%d,%d,%d,%d",iYear,iMonth,iDay,iHour,iMin,iSec);
          sprintf(szDateTime,"dddddd",iYear,iMonth,iDay,iHour,iMin,iSec);
          return 0;
          }
          typedefstruct
          {
          unsignedintYear;
          unsignedintMonth;
          unsignedintDate;
          unsignedintHours;
          unsignedintMinutes;
          unsignedintSeconds;
          }BuildDateTime;

          constunsignedcharMonthStr[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

          voidGetBuildDateTime(BuildDateTime*p_BuildDateTime)
          {
          unsignedchartemp_str[4]={0,0,0,0},i=0;

          sscanf(__DATE__,"%s - M",temp_str,&(p_BuildDateTime->Date),&(p_BuildDateTime->Year));
          sscanf(__TIME__,"-:-:-",&(p_BuildDateTime->Hours),&(p_BuildDateTime->Minutes),&(p_BuildDateTime->Seconds));
          for(i=0;i<12;i++)
          {
          if(temp_str[0]==MonthStr[i][0]&&temp_str[1]==MonthStr[i][1]&&temp_str[2]==MonthStr[i][2])
          {
          p_BuildDateTime->Month=i+1;
          break;
          }
          }
          }
          使用方法示例:
          BuildDateTimeMyBuildDateTime;

          GetBuildDateTime(&MyBuildDateTime);

          RTC_YEAR=MyBuildDateTime.Year;
          RTC_MONTH=MyBuildDateTime.Month;
          RTC_DATE=MyBuildDateTime.Date;
          RTC_HOURS=MyBuildDateTime.Hours;
          RTC_MINUTES=MyBuildDateTime.Minutes;
          RTC_SECONDS=MyBuildDateTime.Seconds;

          __LINE__ 當(dāng)前語句所在的行號, 以10進制整數(shù)標注.
          __FILE__ 當(dāng)前源文件的文件名, 以字符串常量標注.
          __DATE__ 程序被編譯的日期, 以"Mmm dd yyyy"格式的字符串標注.
          __TIME__ 程序被編譯的時間, 以"hh:mm:ss"格式的字符串標注, 該時間由asctime返回.

          __STDC__ 如果當(dāng)前編譯器符合ISO標準, 那么該宏的值為1
          __STDC_VERSION__ 如果當(dāng)前編譯器符合C89, 那么它被定義為199409L, 如果符合C99, 那么被定義為199901L.

          __STDC_HOSTED__ 如果當(dāng)前系統(tǒng)是"本地系統(tǒng)(hosted)", 那么它被定義為1. 本地系統(tǒng)表示當(dāng)前系統(tǒng)擁有完整的標準C庫.

          本文引用地址:http://www.ex-cimer.com/article/201611/322574.htm



          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();