. Advertisement .
..3..
. Advertisement .
..4..
I want to convert minutes into seconds javascript but I am still a novice at Javascript, your suggestions would be much appreciated. Thank you.
Here is a case study for youfunction convertHMS(value) {
const sec = parseInt(value, 10); // convert value to number if it's string
let hours = Math.floor(sec / 3600); // get hours
let minutes = Math.floor((sec - (hours * 3600)) / 60); // get minutes
let seconds = sec - (hours * 3600) - (minutes * 60); // get seconds
// add 0 if value < 10; Example: 2 => 02
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return hours+':'+minutes+':'+seconds; // Return is HH : MM : SS
}
I’d offer this solution but other way is appreciated
One more solution for your reference and share your answer if you have better answer