VC獲取系統時間 程式執行時間

2021-08-31 08:26:16 字數 1041 閱讀 4261

1.使用ctime類

cstring str;

//獲取系統時間

ctime tm;

tm=ctime::getcurrenttime();

str=tm.format("現在時間是%y年%m月%d日 %x");

messagebox(str,null,mb_ok);

2: 得到系統時間日期(使用getlocaltime)

systemtime st;

cstring strdate,strtime;

getlocaltime(&st);

strdate.format("%4d-%2d-%2d",st.wyear,st.wmonth,st.wday);

strtime.format("%2d:%2d:%2d",st.whour,st.wminute,st.wsecond) ;

afxmessagebox(strdate);

afxmessagebox(strtime);

3.使用gettickcount

//獲取程式執行時間

long t1=gettickcount();//程式段開始前取得系統執行時間(ms)

sleep(500);

long t2=gettickcount();();//程式段結束後取得系統執行時間(ms)

str.format("time:%dms",t2-t1);//前後之差即 程式執行時間

afxmessagebox(str);

//獲取系統執行時間

long t=gettickcount();

cstring str,str1;

str1.format("系統已執行 %d時",t/3600000);

str=str1;

t%=3600000;

str1.format("%d分",t/60000);

str+=str1;

t%=60000;

str1.format("%d秒",t/1000);

str+=str1;

afxmessagebox(str);

VC獲取系統時間 程式執行時間

1.使用ctime類 cstring str 獲取系統時間 ctime tm tm ctime getcurrenttime str tm.format 現在時間是 y年 m月 d日 x messagebox str,null,mb ok 2 得到系統時間日期 使用getlocaltime syst...

VC 獲取程式執行時間和系統執行時間

cstring str,str1 獲取程式執行時間 long t1 gettickcount 程式段開始前取得系統執行時間 ms sleep 500 afxmessagebox do something.long t2 gettickcount 程式段結束後取得系統執行時間 ms str.forma...

獲取程式執行時間

獲取程式執行時間,對程式效能進行度量。include double start clock 段 system 程式名.exe 僅對於dos double end clock double time double end begin clocks per sec 1000 ms include dwo...