Dev HelpersOpen library
← Back

Format a duration

Format a duration. A self-contained example using the JavaScript runtime.

Open this example in the interactive library

Source code

const seconds = 3671;
console.log(
  [Math.floor(seconds / 3600), Math.floor(seconds / 60) % 60, seconds % 60]
    .map((n) => String(n).padStart(2, "0"))
    .join(":"),
);

Sample output

01:01:11