function timeRemaining(ms) {
var year = 365.25,
day = 24,
hour = 60,
minute = hour,
second = 1000,
years = ms / ( year * day * hour * minute * second ),
days = years % 1 * year, hours = days % 1 * day,
minutes = hours % 1 * hour,
seconds = minutes % 1 * minute;
return ( years >= 1
? pluralize( Math.floor(years), '', 'год', 'года', 'лет' )
+ ' ' : '' ) + ( days >= 1
? pluralize( Math.floor(days), 'д', 'ень', 'ня', 'ней' )
+ ' ' : '' ) + ( hours >= 1
? pluralize( Math.floor(hours), 'час', '', 'а', 'ов' ) + ' ' : '' )
+ ( minutes >= 1
? pluralize( Math.floor(minutes), 'минут', 'у', 'ы', '' ) + ' ' : '' )
+ pluralize( Math.round(seconds), 'секунд', 'у', 'ы', '' );
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script src="js/common.js"></script>
</head>
<body style="font: 14px/1.5em Arial">
Скачивание начнется через <span id="remaining"></span>
</body>
<script>
var remaining = document.getElementById('remaining'),
time = 150000,
step = 999,
interval = setInterval(function() {
if (time < 0) {
alert('Время вышло');
return clearInterval(interval);
}
remaining.innerHTML = timeRemaining(time);
time -= step;
}, step);
remaining.innerHTML = timeRemaining(time);
</script>
</html>