After several days of struggle, I finally found a solution today. Please share it with me:
The time zone may occur during the renewal:
1. non-renewal:
2. Renewal:
3. Code:
It is also a subtraction of two times. Why is the daylight saving time different from the non-Daylight Saving Time? This is actually the rule of daylight saving time. At the end of March every year, the system clock will automatically Jump faster than an hour during the hour, the specific operation is that when the clock goes to, the next minute is; if the clock is switched to non-clock, it is generally in early November, when the clock goes to, the next moment is.
The two times I calculated above actually pass through the hour. If you calculate it carefully (181-180,958 33333 ..) * 24. The result is exactly one hour, that is, the computing duration is less than one hour during the Failover. This is the root cause of program errors. Find the cause and find a solution.
4. solution:
/// <summary>/// Fixed TimeZone issue: Transfer the sDate1 and sDate2 to UTC, then minus./// </summary>this.dateDiff = function (sDate1, sDate2){//var days = parseInt((sDate1 - sDate2) / 1000 / 60 / 60 / 24);var d1 = Date.UTC(sDate1.getFullYear(), sDate1.getMonth(), sDate1.getDate(), sDate1.getHours(), sDate1.getMinutes(), sDate1.getSeconds(), sDate1.getMilliseconds());var d2 = Date.UTC(sDate2.getFullYear(), sDate2.getMonth(), sDate2.getDate(), sDate2.getHours(), sDate2.getMinutes(), sDate2.getSeconds(), sDate2.getMilliseconds());var days = (d1 - d2) / 1000 / 60 / 60 / 24;return days;}
During time subtraction, find the UTC [also called GMT, Greenwich Mean] time corresponding to the current time, and then subtract it with two UTC time, the result will not change with the time zone.
If you have good methods or insights, please share them with me.