如果我有一个允许某人选择任何开始日期(MM / DD / YYYY)和任何结束日期(MM / DD / YYYY)的表格,我将如何计算这两个选定日期之间的差额? >
我在这里做错了什么?谢谢您的帮助。
<script>
var date1 = new Date();
var date2 = new Date();
var diff = date2.getTime() - date1.getTime();
var msec = diff;
var hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
var mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
var ss = Math.floor(msec / 1000);
msec -= ss * 1000;
function timeElapsed() {
var text = hh + ":" + mm + ":" + ss;
document.getElementById("elapse").innerHTML = text;
}
</script>
答案 0 :(得分:0)
是
let diff = (date2.getTime() - date1.getTime())
会让您与众不同
用
进行转换let diffInDay = diff / 1000 * 60 * 60 * 24