Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save laminr/571b4cc65dd734d4345209a3dca3cd4c to your computer and use it in GitHub Desktop.

Select an option

Save laminr/571b4cc65dd734d4345209a3dca3cd4c to your computer and use it in GitHub Desktop.
Handle Daylight Savings Time (DST) in Javascript.
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