1function convertHMS(value) {
2 const sec = parseInt(value, 10); // convert value to number if it's string
3 let hours = Math.floor(sec / 3600); // get hours
4 let minutes = Math.floor((sec - (hours * 3600)) / 60); // get minutes
5 let seconds = sec - (hours * 3600) - (minutes * 60); // get seconds
6 // add 0 if value < 10; Example: 2 => 02
7 if (hours < 10) {hours = "0"+hours;}
8 if (minutes < 10) {minutes = "0"+minutes;}
9 if (seconds < 10) {seconds = "0"+seconds;}
10 return hours+':'+minutes+':'+seconds; // Return is HH : MM : SS
11}
12
1function secondsToHms(d) {
2 d = Number(d);
3 var h = Math.floor(d / 3600);
4 var m = Math.floor(d % 3600 / 60);
5 var s = Math.floor(d % 3600 % 60);
6
7 var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
8 var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
9 var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
10 return hDisplay + mDisplay + sDisplay;
11}
1const millisToMinutesAndSeconds = (millis) => {
2 var minutes = Math.floor(millis / 60000);
3 var seconds = ((millis % 60000) / 1000).toFixed(0);
4 //ES6 interpolated literals/template literals
5 //If seconds is less than 10 put a zero in front.
6 return `${minutes}:${(seconds < 10 ? "0" : "")}${seconds}`;
7}
8