如何用vc 获取系统时间和程序运行时间.doc
上传人:qw****27 上传时间:2024-09-12 格式:DOC 页数:7 大小:44KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

如何用vc 获取系统时间和程序运行时间.doc

如何用vc获取系统时间和程序运行时间.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

标题:如何用vc++获取系统时间和程序运行时间出处:春天的事业时间:Mon,22Jun200917:34:26+0000作者:xiechunye地址:http://www.xiechunye.cn/read.php/612.htm内容:Q:如何获取时间?精度如何?A:1使用time_ttime(time_t*timer)精确到秒计算时间差使用doubledifftime(time_ttimer1,time_ttimer0)2使用clock_tclock()得到的是CPU时间精确到1/CLOCKS_PER_SEC秒3使用DWORDGetTickCount()得到的是系统运行的时间精确到毫秒4如果使用MFC的CTime类,可以用CTime::GetCurrentTime()精确到秒5要获取高精度时间,可以使用BOOLQueryPerformanceFrequency(LARGE_INTEGER*lpFrequency)获取系统的计数器的频率BOOLQueryPerformanceCounter(LARGE_INTEGER*lpPerformanceCount)获取计数器的值然后用两次计数器的差除以Frequency就得到时间。6还有David的文章中提到的方法:MultimediaTimerFunctionsThefollowingfunctionsareusedwithmultimediatimers.timeBeginPeriod/timeEndPeriod/timeGetDevCaps/timeGetSystemTimetimeGetTime/timeKillEvent/TimeProc/timeSetEvent精度很高Q:GetTickCount()函数,说是毫秒记数,是真的吗,还是精确到55毫秒?A:GetTickCount()和GetCurrentTime()都只精确到55ms(1个tick就是55ms)。如果要精确到毫秒,应该使用timeGetTime函数或QueryPerformanceCounter函数。具体例子可以参考QA001022"VC++中使用高精度定时器"、QA001813"如何在Windows实现准确的定时"和QA004842"timeGetTime函数延时不准"。Q:vc++怎样获取系统时间,返回值是什么类型的变量呢?GetSystemTime返回的是格林威志标准时间GetLocalTime,和上面用法一样,返回的是你所在地区的时间,中国返回的是北京时间VOIDGetSystemTime(LPSYSTEMTIMElpSystemTime//addressofsystemtimestructure);函数就可以获得了,其中LPSYSTEMTIME是个结构体含:年,月,日,周几,小时,分,秒,毫秒。以下是Time的MSDN文档:CompatibilityintheIntroduction.LibrariesLIBC.LIBSinglethreadstaticlibrary,retailversionLIBCMT.LIBMultithreadstaticlibrary,retailversionMSVCRT.LIBImportlibraryforMSVCRT.DLL,retailversionReturnValuetimereturnsthetimeinelapsedseconds.Thereisnoerrorreturn.ParametertimerStoragelocationfortimeRemarksThetimefunctionreturnsthenumberofsecondselapsedsincemidnight(00:00:00),January1,1970,coordinateduniversaltime,accordingtothesystemclock.Thereturnvalueisstoredinthelocationgivenbytimer.ThisparametermaybeNULL,inwhichcasethereturnvalueisnotstored.Example/*TIMES.Cillustratesvarioustimeanddatefunctionsincluding:*time_ftimectimeasctime*localtimegmtimemktime_tzset*_strtime_strdatestrftime**Alsotheglobalvariable:*_tzname*/#include<time.h>#include<stdio.h>#