📌  相关文章
📜  在javascript代码示例中获取两个日期之间的所有日期

📅  最后修改于: 2022-03-11 15:01:10.793000             🧑  作者: Mango

代码示例2
// Returns an array of dates between the two dates
function getDates (startDate, endDate) {
  const dates = []
  let currentDate = startDate
  const addDays = function (days) {
    const date = new Date(this.valueOf())
    date.setDate(date.getDate() + days)
    return date
  }
  while (currentDate <= endDate) {
    dates.push(currentDate)
    currentDate = addDays.call(currentDate, 1)
  }
  return dates
}

// Usage
const dates = getDates(new Date(2013, 10, 22), new Date(2013, 11, 25))
dates.forEach(function (date) {
  console.log(date)
})