Created
April 25, 2019 15:54
-
-
Save thadeu/fd93641c13bd49b9b2491cab5928cb24 to your computer and use it in GitHub Desktop.
Polyfill DateTimeLocal HTML5
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.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