Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

HTML

<input type="datetime-local" onblur="window.setValue(this.value)" />

enter image description here

JS

window.setValue = function (val) {
    console.log(val);
}

The output above is 1991-03-02T00:01, how to get the exact value? Like 03/02/1991 12:01 AM.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
290 views
Welcome To Ask or Share your Answers For Others

1 Answer

function formatDate(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;
  return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + " " + time;
}

var date = new Date();
var output = formatDate(date);
alert(output);

Demo http://jsfiddle.net/64oyzhng/3/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...