2021-09-01 2021-09-30 29天
2021-09-01 2021-10-10 31天 为什么不是30天呢
function dateDiff(beginTime, endTime) {
var aDate, oDate1, oDate2, days;
aDate = beginTime.split("-");
console.log(aDate);
oDate1 = new Date(aDate[0], aDate[1], aDate[2]);
console.log(oDate1);
aDate = endTime.split("-");
oDate2 = new Date(aDate[0], aDate[1], aDate[2]);
days = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);
return days;
}
计算2个日期之间相差多少天
摘录至:20 个杀手级 JavaScript 单行代码