我想将时间和日期输入的值组合到一个日期对象中。
<div id="picker">
Date: <input type="date" name="date" value="2099-08-01" id="date_"/>
Time: <input type="time" name="time" value="20:00" id="time_"/>
</div>
<script>
var d = document.getElementById("date_").valueAsDate;
var t = document.getElementById("time_").valueAsDate
//?
</script>
我如何实现这一目标?
答案 0 :(得分:0)
// create Date object from valid string inputs
var datetime = new Date(date+' '+time);
// format the output
var month = datetime.getMonth()+1;
var day = datetime.getDate();
var year = datetime.getFullYear();
var hour = this.getHours();
if (hour < 10)
hour = "0"+hour;
var min = this.getMinutes();
if (min < 10)
min = "0"+min;
var sec = this.getSeconds();
if (sec < 10)
sec = "0"+sec;
// put it all togeter
var dateTimeString = month+'/'+day+'/'+year+' '+hour+':'+min+':'+sec;