Created
October 24, 2017 22:53
-
-
Save mattgaspar/9981a0b0578f25c26402967028f623d1 to your computer and use it in GitHub Desktop.
Browser timezone/dst detection
This file contains 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 date = new Date(); | |
var jan = new Date(date.getFullYear(), 0, 1); | |
var jul = new Date(date.getFullYear(), 6, 1); | |
// Offset is in minutes | |
var stdTimezoneOffset = Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); | |
// Convert to local machine timezone for date object in PST | |
var timezoneDiffFromPST = stdTimezoneOffset - 480; | |
date += timezoneDiffFromPST * 60 * 60 * 1000; | |
var isDST = date.getTimezoneOffset() < stdTimezoneOffset; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment