美文网首页
根据起始日期罗列出中间所有的日期

根据起始日期罗列出中间所有的日期

作者: tenro | 来源:发表于2022-04-24 14:22 被阅读0次
      getBetweenDateList(start, end) {
          let result = [];
          let beginDay = start.split('-');
          let endDay = end.split('-');
          let diffDay = new Date();
          let dateList = new Array();
          let i = 0;
         diffDay.setDate(beginDay[2]);
         diffDay.setMonth(beginDay[1] - 1);
         diffDay.setFullYear(beginDay[0]);
         result.push(start);
         while (i == 0) {
                let countDay = diffDay.getTime() + 24 * 60 * 60 * 1000;
                diffDay.setTime(countDay);
                dateList[2] = diffDay.getDate();
                dateList[1] = diffDay.getMonth() + 1;
                dateList[0] = diffDay.getFullYear();
                if (String(dateList[1]).length == 1) {
                          dateList[1] = '0' + dateList[1];
                }
                if (String(dateList[2]).length == 1) {
                        dateList[2] = '0' + dateList[2];
                }
                result.push(dateList[0] + '-' + dateList[1] + '-' + dateList[2]);
                if (dateList[0] == endDay[0] && dateList[1] == endDay[1] && dateList[2] == endDay[2]) {
                        i = 1;
                }
          }
          console.log(result);
          return result;
      },
    }

    相关文章

      网友评论

          本文标题:根据起始日期罗列出中间所有的日期

          本文链接:https://www.haomeiwen.com/subject/nnytyrtx.html