Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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