Created
July 6, 2010 12:47
-
-
Save adambabik/465338 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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