1
0

date.js 845 B

1234567891011121314151617181920212223
  1. function f(n) { // Format integers to have at least two digits.
  2. return n < 10 ? '0' + n : n;
  3. }
  4. Date.prototype.rfc3339 = function() {
  5. return this.getUTCFullYear() + '-' +
  6. f(this.getUTCMonth() + 1) + '-' +
  7. f(this.getUTCDate()) + 'T' +
  8. f(this.getUTCHours()) + ':' +
  9. f(this.getUTCMinutes()) + ':' +
  10. f(this.getUTCSeconds()) + 'Z';
  11. };
  12. // This is a format that collates in order and tends to work with
  13. // JavaScript's new Date(string) date parsing capabilities, unlike rfc3339.
  14. Date.prototype.toJSON = function() {
  15. return this.getUTCFullYear() + '/' +
  16. f(this.getUTCMonth() + 1) + '/' +
  17. f(this.getUTCDate()) + ' ' +
  18. f(this.getUTCHours()) + ':' +
  19. f(this.getUTCMinutes()) + ':' +
  20. f(this.getUTCSeconds()) + ' +0000';
  21. };