Показать сообщение отдельно
  #14 (permalink)  
Старый 02.12.2013, 19:32
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,123

iskander83,
<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  #timer div, .timeWords div{
      display: inline;
      
  }

  </style>
</head>

<body>
<div id="timer">
            <div id="d"  class="blueDigit" >00</div>

                <div id="h"   class="blueDigit">00</div>
      <span>:</span>
                <div id="m"   class="blueDigit">00</div>
     <span>:</span>
                <div id="s"  class="redDigit">01</div>
              </div>
              <div class="timeWords" >
                <div id="ds" >дня</div>

                <div id="hs">часов</div>

                <div id="ms">минут</div>

                <div id="ss">секунд</div>

            </div>

<script>
 document.getElementsByTagName("body")[0].onload=setTimer;

function setTimer()
{
    var now = new Date();
	var date=now.getDate();
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	if (month==12) {month=0;year++};
	switch(month) {
		case 0:month="January";break
		case 1:month="February";break
		case 2:month="March";break
		case 3:month="April";break
		case 4:month="May";break
		case 5:month="June";break
		case 6:month="July";break
		case 7:month="August";break
		case 8:month="September";break
		case 9:month="October";break
		case 10:month="November";break
		case 11:month="December";break
	}
	var daysReal;
	var FullDate=year+","+month+",1";
    var endOfTimer = new Date(FullDate);
    var ms = (endOfTimer.getTime()-now.getTime());
	daysReal= Math.floor(ms/(1000*60*60*24));
    if (ms>1)
    {
        var sec=(parseInt(ms/1000));
        var days=(parseInt(sec/(24*60*60)));
        var secInLastDay=sec-days*24*3600;
        var hours=(parseInt(secInLastDay/3600));
        var secInLastHour=secInLastDay-hours*3600;
        var minutes=(parseInt(secInLastHour/60));
        var lastSec=secInLastHour-minutes*60;
		document.getElementById('d').innerHTML = daysReal;
		document.getElementById('h').innerHTML = ((hours<10)?(hours="0"+hours): hours);
		document.getElementById('m').innerHTML = ((minutes<10)?(minutes="0"+minutes): minutes);
		document.getElementById('s').innerHTML = ((lastSec<10)?(lastSec="0"+lastSec): lastSec);
		var daysStr = "дня";
		if(days==0 || days >= 5) daysStr = "дней"; else if(days==1)daysStr="день";
		var hourStr = "часов";
		if((hours>=2 && hours<=4) || hours>=22) hourStr="часа"; else if(hours==1 || hours==21) hourStr='час';
		var minStr="минут";
		if(minutes%10==1 && Math.floor(minutes/10)!=1) minStr="минута"; else if ((minutes%10>=2 && minutes%10<=4) && Math.floor(minutes/10)!=1) minStr="минуты";
		var secStr ="секунд";
		if(lastSec%10==1 && Math.floor(lastSec/10)!=1) secStr="секунда"; else if ((lastSec%10>=2 && lastSec%10<=4) && Math.floor(lastSec/10)!=1) secStr="секунды";
		document.getElementById('ds').innerHTML = daysStr;
		document.getElementById('hs').innerHTML = hourStr;
		document.getElementById('ms').innerHTML = minStr;
		document.getElementById('ss').innerHTML = secStr;
        setTimeout(setTimer,1000)
    }



}

</script>
</body>

</html>
Ответить с цитированием