<h2>Start CountDown(11 dec, 2027, 11:59:59) PM</h2>
<p id="countdown"></p>
clockfun();
function clockfun(){
let presenttime=new Date().getTime();
let settime=new Date(2027,11,31,23,59,59).getTime();
let epic=settime-presenttime;
let day=Math.floor(epic/(86400*1000));
let hour=Math.floor((epic%(86400*1000))/(3600*1000));
let minite=Math.floor((epic%(3600*1000))/(60*1000));
let sec=Math.floor((epic%(60*1000))/(1000));
document.getElementById("countdown").innerHTML=day+"d "+hour+"h "+minite+"m "+sec+"s";
}
setInterval(clockfun,1000);
We can use setTimeout(clockfun, 1000) instead of setInterval(clockfun, 1000) inside the clockfun() function.
#countdown{
background-color:dodgerblue;
display: flex;
align-items: center;
color: white;
border-radius: 8px;
justify-content: center;
padding: 15px 10px;
font-size: 50px;
font-family: monospace;
font-weight: bold;
}