📌  相关文章
📜  在js中将日期范围转换为日期数组 - Javascript代码示例

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

代码示例1
function dateRange(startDate, endDate, steps = 1) {
  const dateArray = [];
  let currentDate = new Date(startDate);

  while (currentDate <= new Date(endDate)) {
    dateArray.push(new Date(currentDate));
    // Use UTC date to prevent problems with time zones and DST
    currentDate.setUTCDate(currentDate.getUTCDate() + steps);
  }

  return dateArray;
}

const dates = dateRange('2020-09-27', '2020-10-28');
console.log(dates);