直接上demo代码和截图
btnClick() {
var oneDay = 1000 * 60 * 60 * 24;
var days = 0;
// dates是一个时间范围,startDate是时间范围的开始时间,endDate是结束时间
var startDate = this.dates[0];
var endDate = this.dates[1];
if (endDate.getTime() > 0 && startDate.getTime() > 0) {
while (endDate.getTime() - startDate.getTime() >= 0) {
if (startDate.getDay() != 6 && startDate.getDay() != 0) {
days++;
}
startDate = new Date(startDate.getTime() + oneDay);
}
console.log(days + "天")
return days;
} else {
return ""
}
}
标签:startDate,dates,endDate,getTime,days,时间差,计算,var,js
From: https://www.cnblogs.com/18sui/p/17312885.html