I am currently working with this block of code:
function startStopwatch() {
vm.lastTickTime = new Date();
$interval.cancel(vm.timerPromise);
vm.timerPromise = $interval(function() {
var tickTime = new Date();
var dateDiff = vm.lastTickTime.getTime() - tickTime.getTime();
var secondsDiff = Math.abs(dateDiff / 1000);
vm.secondsElapsed += Math.round(secondsDiff);
vm.formattedSecondsElapsed = moment.duration(secondsElapsed, "seconds").format("HH:mm:ss");
vm.lastTickTime = tickTime;
}, 1000);
}
This code tracks the number of seconds since hitting the 'play' button on a stopwatch.
The current format increments as 01
, 02
.... up to 60 and then switches to 01:01
, 01:02
, etc.
My goal is to have it formatted as 00:00:00
, incrementing the integer. I have searched for solutions in different programming languages but haven't found one specifically for JavaScript. Any suggestions or assistance would be greatly appreciated!