VC++編程中擷取系統時間,vc編程

來源:互聯網
上載者:User

VC++編程中擷取系統時間,vc編程

<span style="white-space:pre"></span>總結了在程式中如何獲得系統時間的方法
void CGetSystenTimeDlg::OnBnClickedGettimeButton(){// TODO: 在此添加控制項通知處理常式代碼//方法一  使用MFC的CTime類CString str; //擷取系統時間  CTime tm; tm=CTime::GetCurrentTime();   str=tm.Format("現在時間是%Y年%m月%d日 %X"); MessageBox(str,NULL,MB_OK); ////方法二  使用win32定義得結構體SYSTEMTIME time;CString str1,str2;GetLocalTime(&time);  //Windows API 函數,用來擷取當地的當前系統日期和時間。str1.Format(L"%d-%d-%d",time.wYear,time.wMonth,time.wDay);str2.Format(L"%2d:%2d:%2d",time.wHour,time.wMinute,time.wSecond);MessageBox(str1,NULL,MB_OK);MessageBox(str2,NULL,MB_OK);//方法三:GetTickCount返回(retrieve)從作業系統啟動所經過的毫秒數//,它的傳回值是DWORD。 可以用它來測配量序的已耗用時間CString str3;long t1=GetTickCount();//程式段開始前取得系統已耗用時間(ms)   Sleep(500); long t2=GetTickCount();//程式段結束後取得系統已耗用時間(ms)   str3.Format(L"time:%dms",t2-t1);//前後之差即 程式已耗用時間   AfxMessageBox(str3);//擷取系統已耗用時間    即休眠的的時間   //從作業系統啟動所經過的時間 long t=GetTickCount(); CString str4; CString str5; str4.Format(L"系統已運行 %d時",t/3600000);  str5=str5+str4;// MessageBox(str4,NULL,MB_OK); t%=3600000;  str4.Format(L"系統已經運行 %d分",t/60000); str5=str5+str4; t%=60000; str4.Format(L"系統已經運行 %d秒",t/1000); str5=str5+str4;  MessageBox(str5,NULL,MB_OK);}

方法一:


方法二:

      

方法三:

    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.