JSFiddle - React, Tailwind, and code Playground
HTML
<div id="timer">0 Hours 0 Minutes 0 Seconds 0 ms </div>
<input type="button" id="start_btn" value="Start">
<input type="button" id="stop_btn" value="Stop">
<input type="button" id="reset_btn" value="Reset">
JavaScript
var time=new Date(0,0,0,0,0,0,0);
var interId;
var ms=0;
function timer() {
document.getElementById('timer').innerHTML=time.getHours()+'Hours '+time.getMinutes()+'Minutes '+time.getSeconds()+'Seconds '+time.getMilliseconds()+'ms ';
time.setMilliseconds(ms++);
}
window.onload=function () {
document.getElementById('start_btn').onclick=stratTime();
document.getElementById('stop_btn').onclick=stopTime();
document.getElementById('reset_btn').onclick=clearTime();
}
function stratTime() {
alert("start_btn");
interId=setInterval(timer,1);
}
function stopTime() {
alert("stop_btn");
clearInterval(interId);
}
function clearTime() {
alert("reset_btn");
time.setTime(0);
}