分钟1-9之前加0

时间:2016-09-06 10:22:24

标签: jquery date time

我通过jQuery获取当前时间,然后根据时间做一些聪明的位来显示/隐藏商店开放标志。

我当前的代码运行良好,除了时间超过一小时的0-9分钟,在这种情况下失败并错误地显示CLOSED语句。原因是时间被渲染为119例如11:09 - 我需要它的时间是1109而不是119.

代码是:

 tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

 function GetClock(){
 var d=new Date();
 var jwdday=d.getDay(),ap;
 var jwdtime = d.getHours() + "" + d.getMinutes(),gp;

 /* sign logic */
 if (jwdday != "0") {
   if((jwdtime < 1800 && jwdtime >= 1400) || (jwdtime < 1300 && jwdtime >= 700)) {
 document.getElementById('signStatus').innerHTML="<img src='http://www.hawkesbury-stores.co.uk/wp-content/themes/HawkSOS/images/core/weareOpen.png' alt='We are currently OPEN' title='We are currently OPEN' class='weareOpen'>";
   }
   else {
     document.getElementById('signStatus').innerHTML="<img src='weareClosed.png' alt='We are currently CLOSED' title='We are currently CLOSED' class='weareClosed'>";
   }
 }
 else if(jwdtime < 1230 && jwdtime >= 700){
 document.getElementById('signStatus').innerHTML="<img src='weareOpen.png' alt='We are currently OPEN' title='We are currently OPEN' class='weareOpen'>";
 }
 else {
 document.getElementById('signStatus').innerHTML="<img src='weareClosed.png' alt='We are currently CLOSED' title='We are currently CLOSED' class='weareClosed'>";
 }


 }

 window.onload=function(){
 GetClock();
 setInterval(GetClock,1000);
 }

1 个答案:

答案 0 :(得分:0)

您似乎在算术上使用小时和分钟(将它们与数字进行比较),因此您可以执行类似

的操作

var jwdtime = 100*d.getHours() + d.getMinutes();