Skip to content

Instantly share code, notes, and snippets.

@leotsem
Created October 24, 2012 12:39
Show Gist options
  • Save leotsem/3945838 to your computer and use it in GitHub Desktop.
Save leotsem/3945838 to your computer and use it in GitHub Desktop.
Convert a Date object to ISO-8601 format
function ISODateString(d){
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment