1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| let getDayDiff = function (time1, time2) {// "YYYY-MM-DD" // let time1Date = new Date(time1); time1Date.setHours(0); time1Date.setMinutes(0); time1Date.setSeconds(0); time1Date.setMilliseconds(0); let time2Date = new Date(time2); time2Date.setHours(0); time2Date.setMinutes(0); time2Date.setSeconds(0); time2Date.setMilliseconds(0); let timeDiff = time1Date.getTime() - time2Date.getTime();//时间差的毫秒数 let dayDiff = Math.floor(timeDiff / (24 * 3600 * 1000));//计算出相差天数 return dayDiff; }
|