VC获取系统时间、程序运行时间

 CString str;
 //获取系统时间
 CTime tm;
 tm=CTime::GetCurrentTime();
 str=tm.Format("现在时间是%Y年%m月%d日  %X");
 MessageBox(str,NULL,MB_OK);


//获取程序运行时间
 long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)
 Sleep(500);
 long t2=GetTickCount();();//程序段结束后取得系统运行时间(ms)
 str.Format("time:%dms",t2-t1);//前后之差即 程序运行时间
 AfxMessageBox(str);

你可能感兴趣的:(系统时间)