-
-
Save illucent/74ff7c17da187f3524a6 to your computer and use it in GitHub Desktop.
Functions to process time and time zones
This file contains hidden or 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