• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How do I set this timer to a specific date?

I want to understand how this timer function works, please can someone help me?
My goal is to set this timer to end: 2021.11.24 12:00 (UTC)


JavaScript:
<script>
                        (function() {
                          var start = new Date;
                          start.setHours(0, 23.5, 0); // 11pm
 
                          function pad(num) {
                          return ("0" + parseInt(num)).substr(-2);
                          }
 
                          function tick() {
                          var now = new Date;
                          if (now > start) { // too late, go to tomorrow
                            start.setDate(start.getDate() + 1);
                          }
                          var remain = ((start - now) / 1000);
                          var hh = pad((0) % 60);
                          var mm = pad((remain / 60) % 60);
                          var ss = pad(remain % 60);
                          document.getElementById('time_hours').innerHTML = hh;
                          document.getElementById('time_minutes').innerHTML = mm;
                          document.getElementById('time_seconds').innerHTML = ss;
                          setTimeout(tick, 1000);
                          }
 
                          document.addEventListener('DOMContentLoaded', tick);
                        })();
</script>
 

Top