Windows API one-day training (70) getsystemtime and getlocaltime Functions

Source: Internet
Author: User

Time is a very important information. For example, when writing a log, you need to output the time and track it. Program When did the error occur. Or when you develop a bank transaction system, you need to record the current transaction time so that you can output reports and print them to credit card users. Different time periods may be used according to different requirements. Currently, UTC and local time are supported. UTC is Greenwich mean time, that is, the global standard time. The local time is relative to UTC. For example, Beijing in China is in the East 8 zone, and it is 8 hours longer than UTC. Generally, the local time is used, that is, the getlocaltime function is called.

The getsystemtime and getlocaltime functions are declared as follows:

Winbaseapi
Void
Winapi
Getsystemtime (
_ Out lpsystemtime
);

Winbaseapi
Void
Winapi
Getlocaltime (
_ Out lpsystemtime
);

Lpsystemtime is the structure for obtaining system time.

An example of calling a function is as follows:
#001
#002 // obtain the system time.
#003 // Cai junsheng 2007/11/11 QQ: 9073204 Shenzhen
#004 void testsystem (void)
#005 {
#006 // obtain the UTC time of the system.
#007 systemtime stutc;
#008: getsystemtime (& stutc );
#009
#010 // display interval.
#011 const int nbufsize = 256;
#012 tchar chbuf [nbufsize];
#013 wsprintf (chbuf, _ T ("UTC: % u/% u: % u % d \ r \ n "),
#014 stutc. wyear, stutc. wmonth, stutc. wday,
#015 stutc. whour, stutc. wminute, stutc. wsecond,
#016 stutc. wmilliseconds, stutc. wdayofweek );
#017 outputdebugstring (chbuf );
#018
#019
#020 // obtain the local time.
#021 systemtime stlocal;
#022: getlocaltime (& stlocal );
#023
#024 // display interval.
#025 wsprintf (chbuf, _ T ("Local: % u/% u: % u % d \ r \ n "),
#026 stlocal. wyear, stlocal. wmonth, stlocal. wday,
#027 stlocal. whour, stlocal. wminute, stlocal. wsecond,
#028 stlocal. wmilliseconds, stlocal. wdayofweek );
#029 outputdebugstring (chbuf );
#030
#031}
#032

The output results of the above two functions during my test are as follows:
UTC: 2007/11/11 1: 53: 1: 46 0
Local: 2007/11/11 9: 53: 1: 46 0

this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/caimouse/archive/2007/11/11/1878569.aspx

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.