Created
May 8, 2011 19:22
-
-
Save beckje01/961617 to your computer and use it in GitHub Desktop.
A simple set of functions for dealing outputting with ISO dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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