Last active
April 7, 2016 14:38
-
-
Save ergoithz/aa0e4ff963c2b7563e9b8ae926590929 to your computer and use it in GitHub Desktop.
Javascript current TZ string (for ISO_8601)
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
/** | |
* This snipped generates the offset part of ISO_8601 datetime strings. | |
* Useful for composed datetime strings as required for APIs complying RFC3339. | |
*/ | |
var | |
tz = (new Date()).getTimezoneOffset(), | |
pad = function (v){ | |
var sv = Math.abs(parseInt(v, 10)).toString(); | |
return '00'.substr(sv.length) + sv; | |
}, | |
tzstr = (tz<0?'+':'-') + pad(tz/60) + ':' + pad(tz%60); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment