Skip to content

Instantly share code, notes, and snippets.

@thadeu
Created April 25, 2019 15:54
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 thadeu/fd93641c13bd49b9b2491cab5928cb24 to your computer and use it in GitHub Desktop.
Save thadeu/fd93641c13bd49b9b2491cab5928cb24 to your computer and use it in GitHub Desktop.
Polyfill DateTimeLocal HTML5
if (!Date.prototype.toDatetimeLocal) {
(function () {
Date.prototype.toDatetimeLocal = function () {
var date = this
var ten = function (i) {
return (i < 10 ? '0' : '') + i;
}
if (date == 'Invalid Date') return false
var YYYY = date.getFullYear()
var MM = ten(date.getMonth() + 1)
var DD = ten(date.getDate())
var HH = ten(date.getHours())
var II = ten(date.getMinutes())
var SS = ten(date.getSeconds())
return YYYY + '-' + MM + '-' + DD + 'T' + HH + ':' + II + ':' + SS;
};
}());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment