<!doctype html>
<html>
<head>
<script>
setInterval(checkDate, 100);
var targetDate = new Date('Mar,31,2012,00:00:00'),
days = ['день', 'дня', 'дней'],
hours = ['час', 'часа', 'часов'],
minutes = ['минута', 'минуты', 'минут'],
secondsArray = ['секунда', 'секунды', 'секунд'];
function checkDate(){
var now = new Date(),
remainSeconds = parseInt((targetDate - now)/1000),
remainDays = '',
remainHours = '',
remainMinutes = '';
if (remainSeconds > 0){
remainDays = parseInt(remainSeconds/(24*60*60));
remainHours = parseInt((remainSeconds - remainDays*24*60*60)/(60*60));
remainMinutes = parseInt((remainSeconds - remainDays*24*60*60 - remainHours*60*60)/(60));
seconds = parseInt(remainSeconds - remainDays*24*60*60 - remainHours*60*60 - remainMinutes*60);
document.getElementById('pasteIt').innerHTML = remainDays + ' ' + getNumEnding(remainDays, days) + ', ' + remainHours + ' ' + getNumEnding(remainHours, hours) + ', ' + remainMinutes +' ' + getNumEnding(remainMinutes, minutes) + ', ' + seconds + ' ' + getNumEnding(seconds, secondsArray);
} else {
document.getElementById('pasteIt').innerHTML = 'Вы всё проспали';
}
}
function getNumEnding(iNumber, aEndings){
var sEnding, i;
iNumber = iNumber % 100;
if (iNumber>=11 && iNumber<=19) {
sEnding=aEndings[2];
}
else {
i = iNumber % 10;
switch (i) {
case (1): sEnding = aEndings[0]; break;
case (2):
case (3):
case (4): sEnding = aEndings[1]; break;
default: sEnding = aEndings[2];
}
}
return sEnding;
}
</script>
</head>
<body>
<p>Осталось: <span id="pasteIt"></span></p>
</body>
</html>