捎一片雪花

文章 评论 浏览 27

捎一片雪花 2022-05-04 10:06:05
const getDateValueOf = (day) => new Date(day).valueOf()
const setLocalStringDate = (value) => new Date(value).toLocaleDateString().replace(///g,'-')

const getDate = (startDay, endDay) => {
    const standardDayValue = 86400 * 1000;
    if (getDateValueOf(startDay) > getDateValueOf(endDay)) {
        return 'input value is not vaild date'
    }
    const intervalDayValue = (getDateValueOf(endDay) - getDateValueOf(startDay)) / standardDayValue
    return Array.from({length: intervalDayValue + 1}).map((item, index) => index * standardDayValue + getDateValueOf(startDay)).map(item => setLocalStringDate(item))
}


getDate('2019-8-29', '2019-10-10')

第 134 题:求两个日期中间的有效日期

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文