求两个日期中间的日期

function rangeDay (day1, day2) {
    const result = []
    const dayTimes = 24*60*60*1000
    const startTime = day1.getTime()
    const range = day2.getTime() - startTime
    let total = 0
    
    while (total <= range && range > 0) {
        result.push(new Date(startTime + total).toLocaleDateString().replace(/\//g, '-'))
        total += dayTimes
    }
    return result
 };

    rangeDay(new Date("2015-02-08"), new Date("2015-03-03"))

    console.log(rangeDay(new Date("2018-12-01"), new Date("2018-12-25")))

    ["2018-12-1", "2018-12-2", "2018-12-3", "2018-12-4", "2018-12-5", "2018-12-6", "2018-12-7", "2018-12-8", "2018-12-9", "2018-12-10", "2018-12-11", "2018-12-12", "2018-12-13", "2018-12-14", "2018-12-15", "2018-12-16", "2018-12-17", "2018-12-18", "2018-12-19", "2018-12-20", "2018-12-21", "2018-12-22", "2018-12-23", "2018-12-24", "2018-12-25"]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值