denik,
остальные месяцы допишите сами
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div id="CountdownClock"><div id="CountdownClockHTML"><span class="daysLeft"></span><span class="timeLeft"></span></div></div>
<script> time_to_x_hour = false;
function PremierTimer(premiere_date) {
if (premiere_date) {
premiere_date = premiere_date.replace(/[а-яё]+/gi, function(a) {
return {
'января': 'January',
'февраля': 'February'
}[a] || a
})
var now = new Date();
var premiere = new Date(premiere_date);
time_to_x_hour = (premiere.getTime() - now.getTime()) / 1000;
}
if (time_to_x_hour <= 0) {
if (document.getElementById('CountdownClockDiv'))
document.getElementById('CountdownClockDiv').style.display = "none";
document.getElementById('CountdownClock').innerHTML = "Событие состоялась";
return;
}
var daysleft = parseInt(time_to_x_hour / (24 * 60 * 60));
if (daysleft < 0) daysleft = 0;
var d = daysleft - Math.floor(daysleft / 10) * 10;
var dd = 0;
if (daysleft > 100) dd = daysleft - Math.floor(daysleft / 100) * 100;
var daysleftFinal;
var text_day;
if (d == 1 && daysleft != 11 && dd != 11) text_day = "День ";
else if (d > 1 && d < 5 && (daysleft < 10 || daysleft > 20) && (!dd || dd > 20 || dd < 5)) text_day = "Дня ";
else if (d >= 0) text_day = "Дней ";
if (daysleft > 0) daysleftFinal = 'Событие через<br /><span class="daysLeft">' + daysleft + ' ' + text_day + '</span><span class="timeLeft">+';
else daysleftFinal = '';
var hours = parseInt((time_to_x_hour - daysleft * (24 * 60 * 60)) / (60 * 60));
var minutes = parseInt((time_to_x_hour - daysleft * (24 * 60 * 60) - hours * (60 * 60)) / 60);
var seconds = parseInt(time_to_x_hour - daysleft * (24 * 60 * 60) - hours * (60 * 60) - minutes * 60);
hours = hours.toString().length > 1 ? hours : "0" + hours;
minutes = minutes.toString().length > 1 ? minutes : "0" + minutes;
seconds = seconds.toString().length > 1 ? seconds : "0" + seconds;
time_to_x_hour--;
if (!document.getElementById('CountdownClockHTML'))
document.getElementById('CountdownClock').innerHTML = "<div id='CountdownClockHTML'></div>";
if (document.getElementById('CountdownClockHTML'))
document.getElementById('CountdownClockHTML').innerHTML = (daysleftFinal) +
hours + ':' +
minutes + ':' +
seconds + '</span>';
setTimeout(function() {
PremierTimer();
}, 1000);
}</script>
<script>$(function(){ PremierTimer('16 февраля 2020,00:00:00'); });</script>