In input, I have a number of seconds.
In output, I want minutes and seconds, on two digits, separated by :
e.g.
- 1 -> 00:01
- 72 -> 01:12
I come up with the following code :
formatTime: function(nbSeconds) {
var min = Math.ceil(nbSeconds/60);
var sec = nbSeconds % 60;
var formattedMin = min.toLocaleString('fr-FR', { minimumIntegerDigits: 2 });
var formattedSec = sec.toLocaleString('fr-FR', { minimumIntegerDigits: 2 });
return formattedMin + ":" + formattedSec;
},
Is there a better way ?