<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<div class="countdown">
<span class="hours"></span>:<span class="minutes"></span>:<span class="seconds"></span>:<span class="ms"></span>
</div>
<script>
(function($){
var date = new Date(),
month = date.getMonth();
day = date.getDate(),
weekDay = date.getDay(),
hours = {
start: new Date(date.getFullYear(), month, day),
end: new Date(date.getFullYear(), month, day)
};
hours.start.setHours(0);
hours.end.setHours(23);
function countDown(){
var date = new Date(),
countHours = ('0' + (hours.end.getHours() - date.getHours())).substr(-2),
countMinutes = ('0' + (59 - date.getMinutes())).substr(-2),
countSeconds = ('0' + (59 - date.getSeconds())).substr(-2),
countMs = (999 - date.getMilliseconds()+''), len = countMs.length;
countMs = len === 3 ? countMs.substr(0,2) : len === 2 ? ('0'+countMs).substr(0,2) : ('00'+countMs).substr(0,2);
if(date.getHours() < hours.start.getHours() || date.getHours() > hours.end.getHours()){
$('.countdown').hide();
} else if($('.countdown').not(':visible')){
$('.countdown').show();
}
$('.countdown .hours').text(countHours);
$('.countdown .minutes').text(countMinutes);
$('.countdown .seconds').text(countSeconds);
$('.countdown .ms').text(countMs);
$('.ms2').text(countMs2);
}
$(function(){
setInterval(function(){
countDown();
}, 10);
});
})(jQuery);
</script>