The aN is from the NaN error, which means Not a Number. That is because by the time you get to the days you already are trying to do 0%0, which does not have a result. The problem is that you use the number of years, months, etc in your % operation. This should work.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 % secondsPerYear;
months = Math.floor(secondsRemaining / secondsPerMonth);
secondsRemaining = secondsRemaining % secondsPerMonth ;
days = Math.floor(secondsRemaining / secondsPerDay);
secondsRemaining = secondsRemaining % secondsPerDay ;
hours = Math.floor(secondsRemaining / secondsPerHour);
secondsRemaining = secondsRemaining % secondsPerHour;
minutes = Math.floor(secondsRemaining / secondsPerMinute);
secondsRemaining = secondsRemaining % secondsPerMinute ;
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;
}
Andrei