Strict RFC3339 does NOT have the milliseconds, but ISO 8601 (Date.prototype.toISOString()) does, so this polyfills it.
Last active
September 21, 2021 05:44
-
-
Save MatthewDaniels/d54a8c33ef1fa44f8fba5645b341878b to your computer and use it in GitHub Desktop.
Polyifill the JS Date object to have a strict RFC 3339 string method
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
if (!Date.prototype.toRFC3339String) { | |
(function () { | |
function pad(number) { | |
if (number < 10) { | |
return '0' + number; | |
} | |
return number; | |
} | |
Date.prototype.toRFC3339String = function () { | |
return this.getUTCFullYear() + | |
'-' + pad(this.getUTCMonth() + 1) + | |
'-' + pad(this.getUTCDate()) + | |
'T' + pad(this.getUTCHours()) + | |
':' + pad(this.getUTCMinutes()) + | |
':' + pad(this.getUTCSeconds()) + | |
'Z'; | |
}; | |
}()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment