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)
//如果是原生你再继续追问吧
function getCountDays() {var curDate = new Date()
/* 获取当前月份 */
var curMonth = curDate.getMonth()
/* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
curDate.setMonth(curMonth + 1)
/* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
curDate.setDate(0)
/* 返回当月的天数 */
return curDate.getDate()
}
//例如, 获取当前月份(现在是3月)的总天数:
getCountDays() // 返回31