Skip to content

Instantly share code, notes, and snippets.

@kekscom
Created November 9, 2015 13:16
Show Gist options
  • Save kekscom/bd4e3d4e356f90050c77 to your computer and use it in GitHub Desktop.
Save kekscom/bd4e3d4e356f90050c77 to your computer and use it in GitHub Desktop.
Date() toISOString() incl. TZ offset
function formatLocalDate() {
var now = new Date(),
tzo = -now.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
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())
+ 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