JSFiddle - React, Tailwind, and code Playground

by maharajan a

HTML

<button>
click me
</button>

JavaScript

$(function() {
var getSeconds=0;
var startInterval=setInterval(function() {
   getSeconds++;
   console.log(getSeconds)
}, 1000);

$('button').on('click',function() {

// total seconds
var seconds = getSeconds;

// calculate seconds
var s = seconds % 60;
// add leading zero to seconds if needed
s = s < 10 ? "0" + s : s;

// calculate minutes
var m = Math.floor(seconds / 60) % 60;
// add leading zero to minutes if needed
m = m < 10 ? "0" + m : m;

// calculate hours
var h = Math.floor(seconds / 60 / 60);

var time = h + ":" + m + ":" + s

alert(time);
clearInterval(startInterval)
});
});