JSFiddle - React, Tailwind, and code Playground
HTML
<div id="timer">
03:00:00
</div>
JavaScript
const dashboard = document.getElementById("timer");
const target = (((d) => {
const starr = dashboard.innerText.split(":");
return d.setHours(
parseInt(starr[0]) + d.getHours(),
parseInt(starr[1]) + d.getMinutes(),
parseInt(starr[2]) + d.getSeconds());
})(new Date()));
const lz = (n) => ((n > 10 ? "" : "0") + n);
const countdown = () => {
const diff = target.valueOf() - (new Date()).valueOf();
const totalSeconds = Math.floor(diff / 1000);
const seconds = totalSeconds % 60;
const totalMinutes = Math.floor(totalSeconds / 60);
const minutes = totalMinutes % 60;
const hours = Math.floor(totalMinutes / 60);
dashboard.innerText = lz(hours) + ":" + lz(minutes) + ":" + lz(seconds);
}
setInterval(countdown, 1000);