in Program development, the time difference comparison is not required. The simplest time comparison method is to extract the current time and subtract it to get the time difference. You can use the getlocaltime () function to retrieve the current time. However, on Windows Mobile and Windows WinCE (Windows Embedded CE) platforms, the systemtime obtained using the getlocaltime () function does not contain microseconds. The solution is to use the gettickcount () function, first look at the following Code .
Int_ Tmain (IntArgc, _ tchar * argv [])
{
Systemtime receivime;
Getlocaltime (& systime );
DWORD tickcount = gettickcount ();
Printf ("Current time = % 04d-% 02d-% 02d % 02d: % 02d: % 02d % d, tick COUNT = % LD \ n", Required ime. wyear, required ime. wmonth, required ime. wday, required ime. whour, required ime. wminute, required ime. wsecond, required ime. wmilliseconds, tickcount );
Sleep (3000 );
Getlocaltime (& systime );
Tickcount = gettickcount ();
Printf ("Sleep 3 seconds \ ncurrent time = % 04d-% 02d-% 02d % 02d: % 02d: % 02d % d, tick COUNT = % LD \ n", Required ime. wyear, required ime. wmonth, required ime. wday, required ime. whour, required ime. wminute, required ime. wsecond, required ime. wmilliseconds, tickcount );
Return0;
}
The execution result is as follows:
As you can see, the getlocaltime () function cannot be used to retrieve microseconds. The gettickcount () function can take out the time interval (elapsed time) at the microsecond level after the system is started. However, you need to note that if the system runs for longer than 49.7 days, the value is reset.
If the time difference calculation precision requires microseconds, use gettickcount () instead of getlocaltime ().