JSFiddle - React, Tailwind, and code Playground
by Sinh Nguyen
JavaScript
let aNum = 233784;
function secondsToHHMMSS(totalSeconds) {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);
const seconds = totalSeconds - (hours * 3600) - (minutes * 60);
console.log(hours);
console.log(minutes);
console.log(seconds);
const hourStr = hours < 10? "0" + hours : hours;
const minuteStr = minutes < 10 ? "0" + minutes : minutes;
const secondsStr = seconds < 10 ? "0" + seconds: seconds
/* // Padding the values to ensure they are two digits
if (hours < 10) { hourStr = "0" + hours; } else {}
if (minutes < 10) { minuteStr = "0" + minutes; }
if (seconds < 10) { secondsStr = "0" + seconds; } */
return hourStr + ':' + minuteStr + ':' + secondsStr;
}
console.log(secondsToHHMMSS(aNum));