Convert Seconds to HH:MM:SS

function secondsToHMS(seconds) {

  const h = Math.floor(seconds / 3600);

  const m = Math.floor((seconds % 3600) / 60);

  const s = seconds % 60;

  return `${h.toString().padStart(2, ‘0’)}:${m.toString().padStart(2, ‘0’)}:${s.toString().padStart(2, ‘0’)}`;

}

console.log(secondsToHMS(3661)); // Output: “01:01:01”

Leave a comment

Your email address will not be published. Required fields are marked *