-
Year countdown timer expression problem
I’m trying to create a timer that countdown from 1 year and displays in years, months, days, minutes and seconds. I found a suitable expression on an adobe forum but when run it populates the day, minute and second fields with NA. The expression is below. Any help in getting this to work would be gratefully received. As you can guess I know just enough about expressions to make myself look stupid.
totalTimeInSeconds = 31400000;
secondsPerMinute = 60;
secondsPerHour = 60 * 60;
secondsPerDay = 60 * 60 * 24;
secondsPerMonth = 60 * 60 * 24 * 30;
secondsPerYear = 60 * 60 * 24 * 30 * 12;secondsRemaining = totalTimeInSeconds;
years = Math.floor(secondsRemaining / secondsPerYear);
secondsRemaining = secondsRemaining % years;months = Math.floor(secondsRemaining / secondsPerMonth);
secondsRemaining = secondsRemaining % months;days = Math.floor(secondsRemaining / secondsPerDay);
secondsRemaining = secondsRemaining % days;hours = Math.floor(secondsRemaining / secondsPerHour);
secondsRemaining = secondsRemaining % hours;minutes = Math.floor(secondsRemaining / secondsPerMinute);
secondsRemaining = secondsRemaining % minutes;seconds = secondsRemaining;
txt = "";
txt += yearleadingZeros(years);
txt += leadingZeros(months);
txt += leadingZeros(days);
txt += leadingZeros(hours);
txt += leadingZeros(minutes);
txt += leadingZeros(seconds);txt;
function yearleadingZeros(i){
x = "0" + Math.floor(i);
return x;}
function leadingZeros(i){
x = "0" + Math.floor(i);
x = ":" + x.substr(x.length-2, 2);
return x;}