Skip to content

Instantly share code, notes, and snippets.

@adambabik
Created July 6, 2010 12:47
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 adambabik/465338 to your computer and use it in GitHub Desktop.
Save adambabik/465338 to your computer and use it in GitHub Desktop.
Number.prototype.putZero = function() {
if (this >= 0 && this < 10) {
return '0' + this;
} else {
return this;
}
};
Date.prototype.toISO8601 = function () {
var _date = {
year: this.getFullYear(),
month: parseInt(this.getMonth()+1),
day: this.getDate().putZero(),
hour: this.getHours().putZero(),
minutes: this.getMinutes().putZero(),
seconds: this.getSeconds().putZero()
};
var new_date = _date.year + '-' + _date.month.putZero() + '-' + _date.day + 'T' + _date.hour + ':' + _date.minutes + ':' + _date.seconds + 'Z';
return new_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment