Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Format a local date as an RFC 3339 date with timezone
function rfc3339(d) {
function pad(n) {
return n < 10 ? "0" + n : n;
}
function timezoneOffset(offset) {
var sign;
if (offset === 0) {
return "Z";
}
sign = (offset > 0) ? "-" : "+";
offset = Math.abs(offset);
return sign + pad(Math.floor(offset / 60)) + ":" + pad(offset % 60);
}
return d.getFullYear() + "-" +
pad(d.getMonth() + 1) + "-" +
pad(d.getDate()) + "T" +
pad(d.getHours()) + ":" +
pad(d.getMinutes()) + ":" +
pad(d.getSeconds()) +
timezoneOffset(d.getTimezoneOffset());
}
@alexnum

This comment has been minimized.

Copy link

@alexnum alexnum commented Jul 18, 2017

Thanks!

@vitto-moz

This comment has been minimized.

Copy link

@vitto-moz vitto-moz commented Mar 6, 2018

Great!
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.