function calcDate(startTime,endTime){
var start = new Date(startTime)
var end = new Date(endTime)
return (end - start)/1000/60/60/24
}
console.log(calcDate('2018-07-10','2018-07-11'))
//表单取值
var startTime = $("#start_time").val()
var endTime = $("#end_time").val()
//调用函数
var day = calcDate(startTime,endTime)
//填入输入框
$("#day).val(day)
//如果是原生你再继续追问吧
<SCRIPT LANGUAGE="JavaScript"><!--
function deal(){
//var Y = 6
//var R ="2009-11-01"
var R = document.getElementById('date').value +''
var Y = document.getElementById('month').value
alert(R)
var year=R.substr(0,4)
var month=R.substr(5,2)
var day=R.substr(8,2)
if((parseInt(month)+parseInt(Y)) >12){
year++
month = parseInt(month) + parseInt(Y) - 12
}else{
month = parseInt(month) + parseInt(Y)
}
alert(year+"-"+month+"-"+day)
R = new Date(year,month,day,00,00,00)
dateNow = new Date()
var diff = R.getTime() - dateNow.getTime()
var days = Math.floor(diff/(1000*60*60*24))
var str = "与今天相差" + days + "天"
if(R >dateNow){
alert("大于今天!"+"\n"+str)
}else{
alert("小于今天!"+"\n"+str)
}
}
//-->
</SCRIPT>
月<input type="text" id="month" value="6">
日期 <input type="text" id="date" value="2009-11-01">
<input type="button" value="submit" onClick="deal()">
这样的吗