Last active
December 19, 2015 11:56
-
-
Save franga2000/3a3a20b5afa88753aef0 to your computer and use it in GitHub Desktop.
Functions to process time and time zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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