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);