Skip to content

Instantly share code, notes, and snippets.

@jamesmusgrave
Last active October 27, 2016 09:33
Show Gist options
  • Save jamesmusgrave/b8a7828aa0c679cdc4997194c296b5d7 to your computer and use it in GitHub Desktop.
Save jamesmusgrave/b8a7828aa0c679cdc4997194c296b5d7 to your computer and use it in GitHub Desktop.
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 d = new Date();
d.setHours(d.getUTCHours() + timezone);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
var ms = d.getMilliseconds();
if (d.dst()) {
h += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment