如何确定在营业时间/工作日内显示的图像
How to determine the image that is displayed during business hours/days?
所以我之前已经问过这个问题了,我收到了以下的答案,这真的很有帮助!然而,假设营业时间为上午9:00 ,下午5:00 关闭太平洋标准时间(加利福尼亚州),周六和周日关闭。
我如何在下面调整它?
还请记住,下面的脚本将根据营业时间触发图像显示/显示/隐藏。所以在上午9:00 PST时间图像说的是'我们是开放的',在下午5:00 图像然后去'我们是关闭的'。谢谢大家,我希望我已经输入了足够的数据/信息让你回答这个问题。
这是一个参考提琴
$(window).load(function(){
// Translate your hours to UTC, example here is using
// Central Standard Time (-0500 UTC)
// Opening hour in UTC is 16, Closing hour is 0 the next day
var d = new Date(),
open = new Date(),
closed = new Date();
// Statically set UTC date for open
open.setUTCHours(16);
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);
// Statically Set UTC date for closing
closed.setUTCDate(d.getUTCDate()+1); // UTC time rotates back to 0, add a day
closed.setUTCHours(0); // UTC hours is 0
closed.setUTCMinutes(0);
closed.setUTCSeconds(0);
closed.setUTCMilliseconds(0);
// Debugging
console.log("user's date:" + d);
console.log("store open time in user's timezone:" + open);
console.log("store close time in user's timezone:" + closed);
console.log(d > open); // user's time is greater than opening time
console.log(d < closed); // is user's time less than closing time
// (you don't have to go home...)
// Test for store open?
if (d > open && d < closed) {
setOpenStatus(true);
} else {
setOpenStatus(false);
}
function setOpenStatus(isOpen) {
$('#opend').toggle(isOpen);
$('#closed').toggle(!isOpen);
}
});
编辑/更新脚本
$(window).load(function(){
// Translate your hours to UTC, example here is using
// Central Standard Time (-0500 UTC)
// Opening hour in UTC is 16, Closing hour is 0 the next day
var d = new Date(),
open = new Date(),
closed = new Date();
// Statically set UTC date for open
open.setUTCHours(16);
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);
// Statically Set UTC date for closing
closed.setUTCDate(d.getUTCDate()+1); // UTC time rotates back to 0, add a day
closed.setUTCHours(0); // UTC hours is 0
closed.setUTCMinutes(0);
closed.setUTCSeconds(0);
closed.setUTCMilliseconds(0);
// Debugging
console.log("user's date:" + d);
console.log("store open time in user's timezone:" + open);
console.log("store close time in user's timezone:" + closed);
console.log(d > open); // user's time is greater than opening time
console.log(d < closed); // is user's time less than closing time
// (you don't have to go home...)
// Test for store open?
if (d > open && d < closed) {
setOpenStatus(true);
}
if (d.getDay() !== 0 && d.getDay() !== 6 && (d > open && d < closed))
else {
setOpenStatus(false);
}
function setOpenStatus(isOpen) {
$('#opend').toggle(isOpen);
$('#closed').toggle(!isOpen);
}
});
把下面几行改成这样,现在有点乱
if (d.getDay() !== 0 && d.getDay() !== 6 && (d >= open && d < closed)) {
setOpenStatus(true);
} else {
setOpenStatus(false);
}
所以你明白了条件,它说:如果不是星期日(d.getDay() !== 0)
或星期六(d.getDay() !== 6)
,当前时间在打开时间(d >= open)
之后或在关闭时间(d < closed)
之前,则设置打开状态,否则(else)
,设置关闭状态
相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何在生成下载文件时显示加载动画
- React重新渲染但未显示正确的组件
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 音频控件在mouseover上显示,在mouseout上淡出
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 显示5秒后隐藏潜水
- 画廊图像未显示
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 高亮显示时编辑文本大小和颜色
- 使用jQuery's的Datepicker仅显示3个工作日
- 使用Javascript获取工作日&突出显示HTML中的文本
- Weekline插件不显示已单击的工作日
- 隐藏具体日期,只显示工作日