SOURCE

var timeArray = ['2021-1-09', '2021-02-1', '2021-05-19']
/**
 *
 * @param timeArray 时间数组['2021-1-12'...]
 * @description 转换时间数组为距第一个时间的相差天数
 */
function transTimeTodiffDays(timeArray) {
    var temOrigin = +new Date(timeArray[0].replaceAll('-', '/'))
    let arrDiffDays = []
    timeArray.forEach((a, i, arr) => {
        let tem = +new Date(a.replaceAll('-', '/'))
        arrDiffDays.push((tem - temOrigin) / 86400000)// 24 * 60 * 60 * 1000 = 86400000
    })
    return arrDiffDays
}
// console.log(transTimeTodiffDays(timeArray))
/**
 *
 * @param days 相差天数
 * @param originDay 原始时间
 * @description 计算下一个时间
 */
function nextTime(originDay, days = 1) {
    if (!originDay) {
        return
    }
    var temOrigin = +new Date(originDay.replaceAll("-", "/"))
    var nextTem = temOrigin + days * 86400000 // 24 * 60 * 60 * 1000 = 86400000
    var time = new Date(nextTem).toLocaleDateString().replaceAll("/", "-")
    return time
}
console.log(nextTime('2021-1-1', 8))
console 命令行工具 X clear

                    
>
console