Determining DST and Its Offset
To check if Daylight Saving Time (DST) is in effect, you can utilize the getTimezoneOffset property, which returns a time difference in minutes from UTC. The key difference lies in the convention:
To determine the DST status, compare the current offset with the standard offset:
Date.prototype.stdTimezoneOffset = function () { var jan = new Date(this.getFullYear(), 0, 1); var jul = new Date(this.getFullYear(), 6, 1); return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); }; Date.prototype.isDstObserved = function () { return this.getTimezoneOffset() < this.stdTimezoneOffset(); };
By calling isDstObserved() on a date object, you can verify if DST is active.
Example:
var today = new Date(); if (today.isDstObserved()) { console.log("Daylight saving time is in effect!"); }
Das obige ist der detaillierte Inhalt vonWie kann ich feststellen, ob die Sommerzeit (DST) gilt?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!