gpt4 book ai didi

javascript - 时刻 isBetween 使用格式不起作用?

转载 作者:行者123 更新时间:2023-11-29 23:20:21 26 4
gpt4 key购买 nike

我设置了 3 个日期,开始、结束和今天。

let start_date = '20-06-2018',
end_date = '20-06-2018',
today = '20-06-2018'

但是当我解析字符串并使用 isBetween 时,它返回 false。

console.log(moment(start_date, 'DD-MM-YYYY').isBetween(moment(today, 'DD-MM-YYYY'), moment(end_date, 'DD-MM-YYYY'))) //false?

虽然开始和结束是同一天,但今天应该是isBetweeen。

最佳答案

参见 isBetween文档和使用包容性参数

Check if a moment is between two other moments, optionally looking at unit scale (minutes, hours, days, etc). The match is exclusive.

Version 2.13.0 introduces inclusivity. A [ indicates inclusion of a value. A ( indicates exclusion. If the inclusivity parameter is used, both indicators must be passed.

let start_date = '20-06-2018',
end_date = '20-06-2018',
today = '20-06-2018'

console.log(moment(start_date, 'DD-MM-YYYY').isBetween(moment(today, 'DD-MM-YYYY'), moment(end_date, 'DD-MM-YYYY')))

console.log(moment(start_date, 'DD-MM-YYYY').isBetween(moment(today, 'DD-MM-YYYY'), moment(end_date, 'DD-MM-YYYY'), null, '[]'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>

关于javascript - 时刻 isBetween 使用格式不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50944826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com