Created
November 11, 2017 18:28
-
-
Save marekcech/6737b160ccb2cbaa4791a9e4d00c8923 to your computer and use it in GitHub Desktop.
returns ISO timezone with offset
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
function() { | |
// Get local time as ISO string with offset at the end | |
var now = new Date(); | |
var tzo = -now.getTimezoneOffset(); | |
var dif = tzo >= 0 ? '+' : '-'; | |
var pad = function(num) { | |
var norm = Math.abs(Math.floor(num)); | |
return (norm < 10 ? '0' : '') + norm; | |
}; | |
return now.getFullYear() | |
+ '-' + pad(now.getMonth()+1) | |
+ '-' + pad(now.getDate()) | |
+ 'T' + pad(now.getHours()) | |
+ ':' + pad(now.getMinutes()) | |
+ ':' + pad(now.getSeconds()) | |
+ '.' + pad(now.getMilliseconds()) | |
+ dif + pad(tzo / 60) | |
+ ':' + pad(tzo % 60); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment