Skip to content

Instantly share code, notes, and snippets.

@beckje01
Created May 8, 2011 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beckje01/961617 to your computer and use it in GitHub Desktop.
Save beckje01/961617 to your computer and use it in GitHub Desktop.
A simple set of functions for dealing outputting with ISO dates
/*
* dateUtils.js
*
* A simple set of utilites for dealing with dates
*
*/
function toISOFormat(date)
{
var out = "";
out += date.getUTCFullYear() + "-" + padDigit(date.getUTCMonth()+1) + "-" + padDigit(date.getUTCDate()) +"T"+padDigit(date.getUTCHours())+":"+padDigit(date.getUTCMinutes())+":"+padDigit(date.getUTCSeconds())+"."+padMili(date.getUTCMilliseconds())+"Z";
return out;
}
function padDigit(number)
{
return (number < 10 ? '0' : '') + number
}
function padMili(number)
{
if(number<10)
{
return "00"+number;
}
else if(number >=10 && number<100)
{
return "0"+number;
}
else
{
return number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment