A simple example of a time counter. Counts down days, hours, minutes and seconds to a set date.
#javascript#date
<script>(function(){// Targeted datevarcountDownDate=newDate("Jun 2, 2025 23:59:59").getTime();// Update the count down every 1 secondvarx=setInterval(function(){// Get current date and timevarnow=newDate().getTime();// Time to the datevartimeToDate=countDownDate-now;// Time calculations for days, hours, minutes and secondsvardays=Math.floor(timeToDate/(1000*60*60*24));varhours=Math.floor((timeToDate%(1000*60*60*24))/(1000*60*60));varminutes=Math.floor((timeToDate%(1000*60*60))/(1000*60));varseconds=Math.floor((timeToDate%(1000*60))/1000);// Display the result in the element with id="counter"document.getElementById("counter").innerHTML=days+"<small>d</small> "+hours+"<small>h</small> "+minutes+"<small>m</small> "+seconds+"<small>s</small> ";// If the countdown is finished, display a message if(timeToDate<0){clearInterval(x);document.getElementById("counter").innerHTML="Countdown finished";}},1000);})();</script>
<divid="counter"></div>