Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save drteresavasquez/2c10dd83ee4004a2b8128792adff7b56 to your computer and use it in GitHub Desktop.

Select an option

Save drteresavasquez/2c10dd83ee4004a2b8128792adff7b56 to your computer and use it in GitHub Desktop.
formatTime.js
function formatTime(ms) {
const totalSeconds = Math.floor(ms / 1000);
const hours = String(Math.floor(totalSeconds / 3600)).padStart(2, '0');
const minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0');
const seconds = String(totalSeconds % 60).padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment