-
Creating a Ticking Down Timer
Hey Creative Cows,
I’m trying to make a timer that ticks down from 97 years in real time. Ideally, it would be:
years:months:days:hours:minutes:seconds
Is this doable?The best I’ve got is the following, which has the first value going down every second, instead of the last:
function decrementNumber(num, leading, modulus) {
num=”” + Math.floor(num-((timefactor % 1) *num)) % modulus;
while (num.length < leading) num=’0’+num;
return num;}
// Variables
years=93;
months=12;
days=364;
hours=24*days;
minutes=60*hours;
seconds=60*minutes;
timefactor=time;// Calculations
years=”” + Math.floor(years-timefactor);
while (years.length < 2) years=’0′ + years;months=decrementNumber(months,2, 12 );
days=decrementNumber(days,2, 28 );
hours=decrementNumber(hours,2, 24 );
minutes=decrementNumber(minutes,2, 60 );
seconds=decrementNumber(minutes,2, 60 );counter=”” + years + “:” + months + “:” + days + “:” + hours + “:” + minutes +”:” + seconds
Any help would be much appreciated! Thanks!