Convert seconds to hh:mm:ss format

Format a whole number of seconds as zero-padded hours, minutes and seconds.

JavaScript Version 1.0.0 · MIT · .md

convert-seconds-to-hh-mm-ss-format.js
function formatSeconds(seconds) { return [Math.floor(seconds / 3600), Math.floor(seconds % 3600 / 60), seconds % 60].map(part => String(part).padStart(2, '0')).join(':'); }

Input & expected output

Input

3725

Expected output

"01:02:05"

The edge case

Input

90061

Expected output

"25:01:01"

Know the limits

  • Hours keep counting past 24. The original toISOString version wrapped around after one day.
  • Input is a non-negative integer number of seconds.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Convert seconds to hh:mm:ss format from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Replaced the toISOString variant, which wrapped after 24 hours, with zero-padded arithmetic that keeps counting hours. Original MDX retained as inert source evidence.

Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/convert-seconds-to-hh-mm-ss-format.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.