Write your LocalTime function yourself (including complete comments, code)

xiaoxiao2021-03-06  43

Write your LocalTime function yourself (including complete comments, code)

// You can see if you are interested in time.

// Use the LocalTime library function in multi-thread in a platform. It is likely that the memory leak will appear whenever the program runs // for a while. Checked why a few nights did not agree. // I can only write my heart, write a localtimes, the function is the same as the LOCALTIME library function. // After you have it, I will no longer worry about the memory of the memory. // If you know that "memory leak" is a big shame. // This LocalTimes has been run for 3 years under multithreading, and there has not been a problem, rest assured.

// Number of days per month, non-leap year const char days [12] = {31, 28, 31, 30, 31, 30, 31}; / * -------------------------------------------------- ---------------------- Function: LocalTimesModification Historyjurassic 2002.1 Created. -------------------- -------------------------------------------------- --- * / void__stdcalllocaltimes (time_t time, long timezone, struct tm * tm_time) {unsigned __int32 n32_Pass4year; __int32 n32_hpery; // calculate the difference time = time-timezone; if (time <0) {time = 0;} // Take a second time TM_TIME-> TM_SEC = (int) (time% 60); time / = 60; // Take a minute TM_TIME-> TM_MIN = (int); TIME / = 60; // Take the past How many four years, 1461 * 24 hours n32_pass4year = (unsigned int) Time / (1461L * 24L)); // Computing Year TM_TIME-> TM_YEAR = (N32_Pass4year << 2) 70; // 4 The remaining hours left in the year Time% = 1461L * 24L; // Calibrate the year of the leap year, calculate the number of hours in the year in the year for (;;) {// one hour number N32_HPERY = 365 * 24; // Judgment Leap Year IF ((TM_TIME-> TM_Year & 3) == 0) {// is a leap year, a year is 24 hours, namely N32_hpery = 24;} if (Time TM_YEAR ; TIME - = N32_HPERY;} // Hour number tm_time-> TM_HOUR = (int) (time% 24); // The remaining number of days left in the year Time / = 24; // Assume that the leap year Time ; // Correction Year of the year Error, calculation month, date IF ((TM_TIME-> TM_Year & 3) == 0) {if (Time> 60) {t (} else {if (Time == 60) {TM_TIME-> TM_MON = 1; TM_TIME-> TM_MDAY = 29; Return;

转载请注明原文地址:https://www.9cbs.com/read-50952.html

New Post(0)