C + + uses the LocalTime function to note the place __jquery

Source: Internet
Author: User
Tags local time

The LocalTime function is used during processing time to convert a UTC time to local time: [CPP] #include <time.h> time_t tmnow = times (NULL); tm *ptmnow = LocalTime (&A
Mp;tmnow)//From the TM structure can be taken to the date of the month and the minute equivalent.
Here localtime returns a TM pointer, and the space is controlled by localtime itself, so it can be problematic if the function is called continuously. Many times we will handle two of times, such as the "Start Time" "End time" of the time period, the following code: [CPP] time_t tmbegin = 1351118531; 2012-10-25 06:42:11 time_t tmend = 1351218731; 2012-10-26 10:32:11 tm* ptmbegin = localtime (&tmbegin); tm* ptmend = LocalTime (&tmend);//The second call modifies the last called TM structure, if
The last data was not saved will be lost//tm* PTM3 = Gmtime (&tmend);//The effect of the above statement, will also overwrite the previous data char ctmbegin1[26], ctmend[26]; Strftime (Ctmbegin, num, "%y%m%d%h%m%s", ptmbegin);//This output will be Tmend time value strftime (ctmend, num, "%y%m%d%h%m%s", ptmend);/*  MSDN contains instructions: Both the 32-bit and 64-bit versions ofgmtime, Mktime, Mkgmtime, and Localtimeall use a single TM structure per Thread for the conversion.
Each call to one of these routines destroys the "result of" the previous call. * * So remember, once you call the LocalTime function, you should immediately remove the contents of the TM structure: [CPP] time_t tmbegin = 1351118531; 2012-10-25 06:42:One time_t tmend = 1351218731;
2012-10-26 10:32:11 Char ctmbegin1[26], ctmend[26]; tm* Ptmbegin = localtime (&tmbegin); strftime (Ctmbegin, num, "%y%m%d%h%m%s", Ptmbegin); tm* ptmend = LocalTime (&tmE nd); Strftime (Ctmend, "%y%m%d%h%m%s", ptmend);//tm* ptm3 = Gmtime (&tmend);


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.