Skip to content

Instantly share code, notes, and snippets.

@ergoithz
Last active April 7, 2016 14:38
Show Gist options
  • Save ergoithz/aa0e4ff963c2b7563e9b8ae926590929 to your computer and use it in GitHub Desktop.
Save ergoithz/aa0e4ff963c2b7563e9b8ae926590929 to your computer and use it in GitHub Desktop.
Javascript current TZ string (for ISO_8601)
/**
* 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