There is this script which works. However the minutes, secondes, days are not plural or singular. Such as "1 seconded" instead of "1 secondes". This is the first part
The other script takes the days, minutes, seconds and makes it plural/singular. However I cant figure out how to call it in the code aboveCode:function cdtd() { var xmas = new Date("December 25, 2012 00:01:00"); var now = new Date(); var timeDiff = xmas.getTime() - now.getTime(); if (timeDiff <= 0) { clearTimeout(timer); document.write("Christmas is here!"); // Run any code needed for countdown completion here } var seconds = Math.floor(timeDiff / 1000); var minutes = Math.floor(seconds / 60); var hours = Math.floor(minutes / 60); var days = Math.floor(hours / 24); hours %= 24; minutes %= 60; seconds %= 60; document.getElementById("daysBox").innerHTML = days; document.getElementById("hoursBox").innerHTML = hours; document.getElementById("minsBox").innerHTML = minutes; document.getElementById("secsBox").innerHTML = seconds; var timer = setTimeout('cdtd()',1000); }
Code:format: function(r){ var out=""; if(r.d != 0){out += r.d +" "+((r.d==1)?"day":"days")+", ";} if(r.h != 0){out += r.h +" "+((r.h==1)?"hour":"hours")+", ";} out += r.m +" "+((r.m==1)?"min":"mins")+", "; out += r.s +" "+((r.s==1)?"sec":"secs")+", "; return out.substr(0,out.length-2); },



Reply With Quote


Bookmarks