#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t ltime;
char tmpbuf[128];
//方法1:分別獲取當前時間,日期
/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\\t\\t\\t\\t%s\\n", tmpbuf ); //打印當前時間
_strdate( tmpbuf );
printf( "OS date:\\t\\t\\t\\t%s\\n", tmpbuf ); //打印當前日期
//方法二:獲取當前時間日期
time(<ime); //獲取從1970至今經過的秒數
cout << ctime(<ime) << endl; //折算成當前時間日期
return 0;
}
=========================================
VC中基于 Windows 的精確定時
http://www.vckbase.com/document/viewdoc/?id=1301
-------------------------------------------------------------------------------------------------------------
//獲取程序運行時間
long t1=GetTickCount();//程序段開始前取得系統運行時間(ms) ;
Sleep(500);
long t2=GetTickCount();();//程序段結束后取得系統運行時間(ms)
str.Format("time:%dms",t2-t1);//前后之差即 程序運行時間
AfxMessageBox(str);