Untitled
unknown
javascript
3 years ago
1.2 kB
2
Indexable
Never
//Countdown const countdown = () => { const countDate = new Date("Feb 15, 2022 22:27:00").getTime(); const now = new Date().getTime(); const gap = countDate - now; console.log(gap); if (gap < 1000) { document.querySelector(".hari").innerHTML = 0; document.querySelector(".jam").innerHTML = 0; document.querySelector(".menit").innerHTML = 0; document.querySelector(".detik").innerHTML = 0; } else { const second = 1000; const minute = second * 60; const hour = minute * 60; const day = hour * 24; //Calculate const textDay = Math.floor(gap / day); const textHour = Math.floor((gap % day) / hour); const textMinute = Math.floor((gap % hour) / minute); const textSecond = Math.floor((gap % minute) / second); // console.log(textHour); document.querySelector(".hari").innerHTML = textDay; document.querySelector(".jam").innerHTML = textHour; document.querySelector(".menit").innerHTML = textMinute; document.querySelector(".detik").innerHTML = textSecond; } }; setInterval(countdown, 1000);