In contrast to a countdown timer, here we will be looking at the opposite a timer ( counter ) that works like a stopwatch.

The code looks like this:

<p>Timer Demo</p>

<p id="demo"></p>

<script>
var start = Date.now();
setInterval(function() {
    // milliseconds elapsed since start
    var delta = Date.now() - start; 
    // convert milliseconds to seconds
    given_seconds = (Math.floor(delta / 1000)); 
    
    // calculate hour/mins/sec's based on given seconds
    hours = Math.floor(given_seconds / 3600);
    minutes = Math.floor((given_seconds - (hours * 3600)) / 60);
    seconds = given_seconds - (hours * 3600) - (minutes * 60);
    
    //Format the time with two digits per hour/mins/sec's
    timeString = hours.toString().padStart(2, '0') + ':' + 
      minutes.toString().padStart(2, '0') + ':' + 
      seconds.toString().padStart(2, '0');
    
    //Print the current time so far
    document.getElementById("demo").innerHTML = timeString;

}, 1000); // update about every second
</script>

Simply copy paste the code to the HTML section in your appearance settings.

You can see a working demo of this here:

https://test2.leadshook.io/survey/ex8YutWr2DAW05wd5vmB18OMAeyreLfUPiedaKWh

Leave a Reply

Your email address will not be published. Required fields are marked *