Use native C ++ time functions in Windows Mobile and Windows WinCE (Windows Embedded CE)

Source: Internet
Author: User

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 ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.