Skip to content

Instantly share code, notes, and snippets.

@xyqfer
Created September 28, 2013 07:06
Show Gist options
  • Save xyqfer/6739386 to your computer and use it in GitHub Desktop.
Save xyqfer/6739386 to your computer and use it in GitHub Desktop.
Date.prototype.toJSON
function f(n) {
return n < 10 ? '0' + n : n;
}
Date.prototype.toJSON = function () {
return isFinite(this.valueOf())
? this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z'
: null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment