$(document).ready(function () { var countDownDate = new Date("Aug 14, 2022 23:59:59").getTime(); var x = setInterval(function () { var now = new Date().getTime(); var distance = countDownDate - now; var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); $("#timer > p > #d").text(days); $("#timer > p > #hh").text(hours<10?"0"+hours:hours); $("#timer > p > #mm").text(minutes<10?"0"+minutes:minutes); $("#timer > p > #ss").text(seconds<10?"0"+seconds:seconds); if (distance < 0) { clearInterval(x); $("#timer").remove();; } }, 1000); });