说明,这四种方法也分别代表了类似的实现,在MFC中,所可以从哪些类集合去考虑。

 

方法一 利用GetTickCount函数(ms)



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


方法二利用C/C++计时函数(s)

 



clock_t   start,   finish; 
start = clock();
。。。。。。//to do sth
finish = clock();
printf("%f seconds\n",(double)(finish-start)/CLOCKS_PER_SEC);


 

方法三 利用CTime类 获取系统时间

 



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


 

方法四  利用GetLocalTime类获取系统时间



SYSTEMTIME st;  
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("M----",st.wYear,st.wMonth,st.wDay);
strTime.Format("-:-:-",st.wHour,st.wMinute,st.wSecond);
AfxMessageBox(strDate);
AfxMessageBox(strTime);


 


你们的评论、反馈,及对你们有所用,是我整理材料和博文写作的最大的鼓励和唯一动力。欢迎讨论和关注!

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。