列出两个日期之间所有的天

//列出两个日期之间所有的天
function ListDate(value1, value2) {
    var dateList = [];
    var getDate = function (str) {
        var tempDate = new Date();
        var list = str.split("-");
        tempDate.setFullYear(list[0]);
        tempDate.setMonth(list[1] - 1);
        tempDate.setDate(list[2]);
        return tempDate;
    }
    var date1 = getDate(value1);
    var date2 = getDate(value2);

    if (date1 == date2) {
        dateList.push(date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate())
        return dateList;
    }

    if (date1 > date2) {
        var tempDate = date1;
        date1 = date2;
        date2 = tempDate;
    }
    while (!(date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate())) {
        dateList.push(date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate());
        date1.setDate(date1.getDate() + 1);
    }
    dateList.push(date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate());
    return dateList;

}
原文地址:https://www.cnblogs.com/twzy/p/5237343.html