JSFiddle - React, Tailwind, and code Playground

Count down timer using date object Note jQuery is not needed at all for the actual counting forked from http://jsfiddle.net/mplungjan/rrjHF/

by dledle2

HTML

<div id="counttime">01:01:00</div>
<div id="cons"></div>

JavaScript

function pad(num) {
      return num<10?"0"+num:num;
    }
    $(function() {
      var tCont = $('#counttime');
      var timer = tCont.html().split(':');
      
      if (timer.length === 2) timer.unshift(0);
      var endMilli= timer[0]*60*60*1000;
      endMilli += timer[1]*60*1000
      endMilli += timer[2]*1000;
      if(endMilli > 0) {
        var endTime = new Date(Date.now()+endMilli);   
$("#cons").append("<br>"+endTime);
        var tId = setInterval(function() {
          var diff = endTime.getTime()-Date.now();
          if (diff<=0) {
            tCont.html("00:00:00");
            clearInterval(tId);
          }
          else {
            var d = new Date(diff);
            hh = pad(d.getUTCHours()); 
            mm = pad(d.getMinutes());
            ss = pad(d.getSeconds());
            tCont.html(""+hh+":"+mm+":"+ss);
          }
        },300);      
      }
    });