如何确定在营业时间/天期间显示的图像? [英] How to determine the image that is displayed during business hours/days?

查看:102
本文介绍了如何确定在营业时间/天期间显示的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经问过这个问题,我收到以下作为答案,真正帮助!但是,假设该商家在上午9:00 开启,并在下午5:00 PST时间(加利福尼亚州)关闭,周六休息



请注意,下面的脚本触发了基于营业时间显示/显示/隐藏的图像。因此,在早上9:00太平洋标准时间时,图片显示为我们打开,在下午5:00 ,图片将显示为我们已关闭。感谢各位,我希望我已经输入足够的数据/信息,为您回答这个问题。



以下是小提琴的参考资料

  $(window).load(function(){
//正在使用
//中央标准时间(-0500 UTC)

// UTC的开放时间为16,第二天的关闭时间为0
var d = new Date ),
open = new Date(),
closed = new Date();

//打开
的静态设置UTC日期open.setUTCHours(16) ;
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);

//静态设置关闭的UTC日期
closed.setUTCDate(d.getUTCDate()+ 1); // UTC时间旋转回0,添加一天
closed.setUTCHours(0); // UTC小时为0
close.setUTCMinutes(0);
closed.setUTCSeconds(0);
closed.setUTCMilliseconds(0);

//调试
console.log 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); //用户的时间大于开放时间
console.log(d< closed); //是用户的时间少于关闭时间
//(你不必回家...)

//测试商店开放?
if(d> open&& d< closed){
setOpenStatus(true);
} else {
setOpenStatus(false);
}

function setOpenStatus(isOpen){
$('#opend')。toggle(isOpen);
$('#closed')。toggle(!isOpen);
}
});






已编辑/更新的脚本

  $(window).load(function b $ b //将您的营业时间转换为UTC,例如,使用
//中央标准时间(-0500 UTC)

// UTC时间为16小时,营业时间为0第二天
var d = new Date(),
open = new Date(),
closed = new Date();

//静态设置UTC打开
的日期open.setUTCHours(16);
open.setUTCMinutes(0);
open.setUTCSeconds(0);
open.setUTCMilliseconds(0);

//静态设置关闭的UTC日期
closed.setUTCDate(d.getUTCDate()+ 1); // UTC时间旋转回0,添加一天
closed.setUTCHours 0); // UTC小时为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); //用户的时间大于开放时间
console.log(d< closed); //是用户的时间少于关闭时间
//(你不必回家...)

//测试商店开放?
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> =打开)之后和在结束时间之前(d <闭合),然后设置打开状态,否则(else),设置关闭状态。


So I already asked this question before and I received the following as an answer which truly helps! However lets say the business opens at 9:00 AM and closes at 5:00 PM PST time (California) and they are closed on Saturday and Sunday.

How can I adjust that below?

Also keep in mind that the script below is triggering an image to show/display/hide based on the business hours. So at 9:00 AM PST time the image say's 'We're Open' and at 5:00 PM the image then goes to 'We're Closed'. Thanks guys I hope I have entered enough data/information for you to answer this question.

Here is a reference Fiddle.

$(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);
  }
});​


EDITED/UPDATED SCRIPT

$(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);
  }
});​

解决方案

Change the bottom few lines to this, it is a little muddled at present.

if (d.getDay() !== 0 && d.getDay() !== 6 && (d >= open && d < closed)) {
    setOpenStatus(true);
} else {
    setOpenStatus(false);
}

So you understand the condition, it says: If it is not Sunday (d.getDay() !== 0) or Saturday (d.getDay() !== 6) and the current time is after or at the opening time (d >= open) and before the closing time (d < closed), then set the open status, otherwise (else), set closed status.

这篇关于如何确定在营业时间/天期间显示的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆