Skip to content

Instantly share code, notes, and snippets.

@franga2000
Last active December 19, 2015 11:56
Show Gist options
  • Save franga2000/3a3a20b5afa88753aef0 to your computer and use it in GitHub Desktop.
Save franga2000/3a3a20b5afa88753aef0 to your computer and use it in GitHub Desktop.
Functions to process time and time zones
//Get UTC/GMT Offset
new Date().getTimezoneOffset() / -60; /* Type: integer */
//Get timezone offset string: GMT, GMT+01:00, GMT-01:30
function getTimeZoneString() {
var num = new Date().getTimezoneOffset();
if (num === 0) {
return "GMT";
} else {
var hours = Math.floor(num / 60);
var minutes = Math.floor((num - (hours * 60)));
if (hours < 10) hours = "0" + Math.abs(hours);
if (minutes < 10) minutes = "0" + Math.abs(minutes);
return "GMT" + (num < 0 ? "+" : "-") + hours + ":" + minutes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment