gpt4 book ai didi

javascript - 如果声明只考虑每小时

转载 作者:行者123 更新时间:2023-11-30 08:00:11 24 4
gpt4 key购买 nike

我如何让我的 if 语句 评估整个时间段,例如,从 06:00:00 到 11:00:00 的每一秒,而不是它在做什么那一刻,它错过了像 06:15:00 这样的时间:

if (time == "6am - 11am") {
if (rideshareTime == "06:00:00" || rideshareTime == "07:00:00" || rideshareTime == "07:00:00" || rideshareTime == "08:00:00" || rideshareTime == "09:00:00" || rideshareTime == "10:00:00" || rideshareTime == "11:00:00") {
if (luggageSpace == "Yes") {
if (rideshareSeats >= seatsAvailable && luggageSpace == rideshareLuggage && womenOnly == rideshareWomen) {
$obj.closest('.rideshare-item').show();
}
} else {
if (rideshareSeats >= seatsAvailable && womenOnly == rideshareWomen) {
$obj.closest('.rideshare-item').show();
}
}
}
}

最佳答案

我建议使用像 momentjs.com 这样的日期/时间库,它是 isBetween 方法。

您可以使用字符串数据类型和它的 substring 方法来解决它。虽然我不推荐它,因为字符串不是用来对日期/时间进行操作的。

if (rideshareTime.substring(0,2) == "06" || rideshareTime.substring(0,2) == "07" || rideshareTime.substring(0,2) == "07" || rideshareTime.substring(0,2) == "08" || rideshareTime.substring(0,2) == "09" || rideshareTime.substring(0,2) == "10" || rideshareTime == "11:00:00")

关于javascript - 如果声明只考虑每小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30152213/

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