-
-
Save laminr/571b4cc65dd734d4345209a3dca3cd4c to your computer and use it in GitHub Desktop.
Handle Daylight Savings Time (DST) in Javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var today = new Date(); | |
| 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.dst = function() { | |
| return this.getTimezoneOffset() < this.stdTimezoneOffset(); | |
| } | |
| var utc_offset = '-7'; | |
| if (today.dst()) { | |
| utc_offset = '-6'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment