I have Javascript code that is basically an expired timer to download a file. Here is the code:
var time = new Date().getTime() - startTime;
var elapsed = Math.floor(time / 100) / 10;
console.log(elapsed);
Using this, I get logs in the console looking like: 0.7, 0.8, 0.9, 1, 1.1, 1.2etc. These are seconds, and the number after .is 10 seconds of a second. I want to format this in a more understandable form for a person, for example, 26 seconds will be 00:26, 1 minute 30 seconds will be 01:30, 20 minutes will be 20:00, etc.
However, I have no idea how to write the function correctly in order to convert it into a readable form.
source
share