const start = body.startDate;
const end =body.endDate;
var dayCount = 0
while (end > start) {
dayCount++
start.setDate(start.getDate() + 1)
}
console.log("datedifferent"+dayCount);
为什么我遇到错误start.getDate()不起作用
答案 0 :(得分:0)
const start = new Date(Date.parse(body.startDate));
const end = new Date(Date.parse(body.endDate));
var dayCount = 0
while (end > start) {
dayCount++
start.setDate(start.getDate() + 1)
}
console.log("datedifferent"+dayCount);
答案 1 :(得分:0)
变量start不是日期对象,因此会出现该错误。
按照Prime用户的答案将开始创建为日期对象。