baozhengrui

导航

将一个时间段进行分割为每一天

function splitIntoDays(start ,end){
    let days = [];
    let currentDay = [];
    while(currentDay <= end){
      days.push(new Date(currentDay));
      currentDay.setDate(currentDay.getDate() +1);
    }
    return days;
}

eg:
  let start = new Date('2024-1-1');
  let end = new Date('2024-1-1');
  let days = splitIntoDays(start,end);

posted on 2024-09-04 17:18  芮艺  阅读(4)  评论(0编辑  收藏  举报