I got an undefiend error passing my date value into formatDate function, why? How to ceate an instance in my case?
function formatDate(date) {
if (date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var format = hours < 12 ? 'am' : 'pm';
hours = hours % 12;
hours = hours ? hours : 12; // making 0 a 12
minutes = minutes < 10 ? '0' + minutes : minutes;
var time = hours + ':' + minutes + ' ' + format;
var output = date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear() + " " + time;
console.log(output);
alert(output);
}
}
<input type="datetime-local" onblur="formatDate(this.value)" />