JSFiddle - React, Tailwind, and code Playground
by maremp
HTML
<div id="timer"></div>
JavaScript
// for output purposes
var timerDiv = document.getElementById("timer");
function setTime(t) {
timerDiv.innerHTML = t;
}
var time = 0;
// time in milliseconds
var startTime = Date.now();
setInterval(function () {
time = Date.now() - startTime;
// divide by 1000 to get seconds and round the value
setTime(Math.round(time / 1000));
}, 1000);
setTime(time);