Javascript Countdown from 8am-9pm -


I have a javascript countdown from 12 a.m. to 9 p.m. every day and then resets itself.

I want to count from 12 a.m. to 9 p.m. instead of 8 a.m. to 9 p.m. I'm negligible with it, but I want to work it out with a start time of 12:00 Can not seem to.

My question is how can I count down from 8-21 hours instead of 0 -21 hours?

Javascript:

  if (document.getElementById ('countdown')) {pad = function (n, len) {// leading 0's var = N.toString (); Returns (new arrays (lane - S.Lump + 1)) .Join ('0')) + s; }; Function countdown () {var now = new date (); If ((now. Gate) (1) & amp; = = 1) & amp; Amp; (Now give the gate); & Lt; = 7)) // // Monday to Sunday var target = 21; // 21: 00 hours is cut-off point if (now. Gates (target)) {// var hrs = (target - 1) - now.gethors (); If (hours and lieutenant; 0) hours = 0; Var mins = 59 - Now. GetMinutes (); If (minutes & lt; 0) mins = 0; Var secs = 59 - Now .getSeconds (); If (secs & lt; 0) seconds = 0; Var str = pad (hour, 2) + ':' + pad (min, 2) + ' & Lt; Small & gt; ' + Pad (second, 2) + '& lt; / Small & gt; '; Document.getElementById ('Countdown'). InnerHTML = str; } And $ ('. OpenOpen'). Hide (); }} Var timerRunning = setInterval ('countdown ()', 1000); }  


I do not fully understand Coming is your question, but do you just type the code from now.getHours () & gt; = 7 , meaning

  ... if (now. Gethours) & Gt; = 7 & amp; Amp; Amp; Now.getHours () & lt; Goal) {...} and {$ ('. OpenOpen'). Hide (); } ...  

Edit

In the light of the comment, the following should work:

  If (document.getElementById ('countdown')) {pad = function (n, len) {// key 0 var s = n.toString (); Returns (new arrays (lane - S.Lump + 1)) .Join ('0')) + s; }; Function countdown () {var now = new date (); If ((now. Gate) (1) & amp; = = 1) & amp; Amp; (Now give the gate); & Lt; = 7)) // // Monday to Sunday var target = 21; // 21: 00hrs cut-off point var hours = now. Gate Horse (); // Get hours (hours & lt; 8 || hours & gt; = target) {$ ('. OpenOpen'). Hide (); Return; } And $ ('Open.'). Show (); Var hours = (goal - 1) - hours; If (hours and lieutenant; 0) hours = 0; Var mins = 59 - Now. GetMinutes (); If (minutes & lt; 0) mins = 0; Var secs = 59 - Now .getSeconds (); If (secs & lt; 0) seconds = 0; Var str = pad (hour, 2) + ':' + pad (min, 2) + ' & Lt; Small & gt; ' + Pad (second, 2) + '& lt; / Small & gt; '; Document.getElementById ('Countdown'). InnerHTML = str; }} Var timerRunning = setInterval ('countdown ()', 1000);  

}


Comments