March 24, 201115 yr Hi all, I have a countdown script. It works great, except I would like it to display in a 48 hour format instead of a 24 hour format; It will only ever be a 48 hour countdown. Eg '47 hours 8 mins 2 secs remaining', rather than '1 day 24 hours 8 mins 2 secs remaining'. Any help would be very appreciated. /*usage*/ <script type="text/javascript"> TargetDate = "03/24/2011 11:59 PM"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%H%% %%M%% %%S%%"; FinishMessage = "Who Pays Full Price Is Ready For Launch!"; </script> //countdown functionality function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return "<span>" + s + "</span>"; } function CountBack(secs) { if (secs < 0) { document.getElementById("countdown").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("countdown").innerHTML = DisplayStr; if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod); } function putspan(backcolor, forecolor) { document.write("<span id='countdown'></span>"); } if (typeof(BackColor)=="undefined") BackColor = "white"; if (typeof(ForeColor)=="undefined") ForeColor= "black"; if (typeof(TargetDate)=="undefined") TargetDate = "12/31/2020 5:00 AM"; if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%% %%H%% %%M%% %%S%%"; if (typeof(CountActive)=="undefined") CountActive = true; if (typeof(FinishMessage)=="undefined") FinishMessage = ""; if (typeof(CountStepper)!="number") CountStepper = -1; if (typeof(LeadingZero)=="undefined") LeadingZero = true; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; putspan(BackColor, ForeColor); var dthen = new Date(TargetDate); var dnow = new Date(); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs);
March 24, 201115 yr **EDIT** Oops - should of read thread properly!! Edited March 24, 201115 yr by Bomb
March 24, 201115 yr Try changing this line: DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); To: DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,7200,48));
March 24, 201115 yr Author Thanks guys, Spitfire - I done this, but i'm still not getting 48 hours? It looks like the script isn't 'allowing' the hour to be counted over 24 hours? Tony
March 24, 201115 yr Thanks guys, Spitfire - I done this, but i'm still not getting 48 hours? It looks like the script isn't 'allowing' the hour to be counted over 24 hours? Tony Sorry, I think I got that wrong. It should be: DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,48)); The way I told you to do it before meant that hours were 120 mins long!
March 24, 201115 yr Author Sorry, I think I got that wrong. It should be: DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,48)); The way I told you to do it before meant that hours were 120 mins long! Haha, thank you ever so much - all working now. I have also learnt something new! Tony
Create an account or sign in to comment