Нужно с помощью Math.floor, у самого не получается сделать.... 17966 дней, а должно быть 20 дней
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<div class="timer">
<span class="timer-text">До конца ации осталось:</span>
<div class="timer-time">
<div class="timer-item">
<span class="timer-item__numbers" id="timer-v-day"></span>
<span id="timer-v-day__text">Дни</span>
</div>
<div class="timer-item">
<span class="timer-item__numbers" id="timer-v-hours"></span>
<span id="timer-v-hours__text">Часы</span>
</div>
<div class="timer-item">
<span class="timer-item__numbers" id="timer-v-minutes"></span>
<span id="timer-v-minutes__text">Минуты</span>
</div>
<div class="timer-item">
<span class="timer-item__numbers" id="timer-v-seconds"></span>
<span id="timer-v-seconds__text">Секунды</span>
</div>
</div>
</div>
<body>
<script src="main.js"></script>
</body>
</html>
var decCache = [],
decCases = [2, 0, 1, 1, 1, 2];
function decOfNum(number, titles) {
if (!decCache[number]) decCache[number] = number % 100 > 4 && number % 100 < 20 ? 2 : decCases[Math.min(number % 10, 5)];
return titles[decCache[number]];
}
function timerLeft(year,month,day) {
setInterval(function() {
var daysLeft = document.getElementById('timer-v-day'),
daysText = document.getElementById('timer-v-day__text'),
hoursLeft = document.getElementById('timer-v-hours'),
hoursText = document.getElementById('timer-v-hours__text'),
minutesLeft = document.getElementById('timer-v-minutes'),
minutesText = document.getElementById('timer-v-minutes__text'),
secLeft = document.getElementById('timer-v-seconds'),
secText = document.getElementById('timer-v-seconds__text'),
dateNow = new Date().getTime(),
dateFinish = new Date(year,month,day),
sec = Math.floor((dateFinish - dateNow) / 1000),
secToMinutes = sec % 3600,
daysNumber = Math.floor(dateNow / (1000 * 60 * 60 * 60));
hoursNumber = Math.floor(sec / 3600),
minutesNumber = Math.floor(secToMinutes / 60),
secondsNumber = secToMinutes % 60;
daysText.innerHTML = decOfNum(daysNumber, ['день', 'дня', 'дней']);
hoursText.innerHTML = decOfNum(hoursNumber, ['час', 'часа', 'часов']);
minutesText.innerHTML = decOfNum(minutesNumber, ['минута', 'минуты', 'минут']);
secText.innerHTML = decOfNum(secondsNumber, ['секунда', 'секунды', 'секунд']);
daysLeft.innerHTML = daysNumber;
hoursLeft.innerHTML = hoursNumber;
minutesLeft.innerHTML = minutesNumber;
secLeft.innerHTML = secondsNumber;
},1000)
}
timerLeft(2019, 02, 31);