Skip to content

Instantly share code, notes, and snippets.

@mattgaspar
Created October 24, 2017 22:53
Show Gist options
  • Save mattgaspar/9981a0b0578f25c26402967028f623d1 to your computer and use it in GitHub Desktop.
Save mattgaspar/9981a0b0578f25c26402967028f623d1 to your computer and use it in GitHub Desktop.
Browser timezone/dst detection
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