gpt4 book ai didi

javascript - 根据日期和时间显示打开或关闭

转载 作者:行者123 更新时间:2023-12-03 09:22:02 25 4
gpt4 key购买 nike

我目前正在使用我在上一篇文章中找到的一些脚本..它根据日期和时间显示打开或关闭..

$(document).ready(function() {
"use strict";
var Now = new Date();
var CurrentDay = Now.getDay();
// opening time - 24 hours so 9:30am is 9, 30
var OpeningTime = new Date(Now.getFullYear(), Now.getMonth(), Now.getDate(), 8);
// closing time - 24 hours so 5:30pm is 17, 30
var ClosingTime = new Date(Now.getFullYear(), Now.getMonth(), Now.getDate(), 20);
var Open = (Now.getTime() > OpeningTime.getTime() && Now.getTime() < ClosingTime.getTime());
// days 0.sun 1.mon 2.tues 3.wed 4.thur 5.fri 6.sat
// CurrentDay !== 0 && the # is the day to eclude, so if I want to be closed on Sat6, Sun0, Wed3
// CurrentDay !== 6 && CurrentDay !== 0 && CurrentDay !== 3 && Open
if (CurrentDay !== 1 && CurrentDay !== 5 && Open) {
$('.openstatus').toggle();
}
});

目前已设置为周一至周五上午 8 点至下午 8 点。但我还想在周六上午 9 点至下午 5 点和周日上午 10 点至下午 4 点之间显示开放文本

如有任何建议,我们将不胜感激。

非常感谢。

https://jsfiddle.net/xncor0b8/

最佳答案

我在这里有一个建议: https://jsfiddle.net/xncor0b8/3/

var startingHour = {
1: 8,
2: 8,
3: 8,
4: 8,
5: 8,
6: 9,
0: 10
};
var startingMin = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
0: 0
}

var closingHour = {
1: 20,
2: 20,
3: 20,
4: 20,
5: 20,
6: 17,
0: 16
};

var closingMin = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
0: 0
};

var CurrentDay = Now.getDay();
var startingTime = new Date(Now.getFullYear(), Now.getMonth(), Now.getDate(), startingHour[CurrentDay], startingMin[CurrentDay]);
var closingTime = new Date(Now.getFullYear(), Now.getMonth(), Now.getDate(), closingHour[CurrentDay], closingMin[CurrentDay]);
var Open = (Now.getTime() > startingTime.getTime() && Now.getTime() < closingTime.getTime());
if (Open) {
$('.openstatus').toggle();
}

将商店营业的小时和分钟定义为 var,并通过配置检查当前时间。

如果开放/关闭时间可能发生变化,似乎更容易更新。

关于javascript - 根据日期和时间显示打开或关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31813201/

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