Seconds to H:MM:SS

Easy ⏱ 8 min 75% acceptance ★★★★★ 4.9
Write hms(total_seconds) formatting a duration as 'H:MM:SS' (hours unpadded, minutes/seconds zero-padded). Use divmod twice — no datetime needed for pure durations.

Examples

Example 1
Input
hms(3725)
Output
'1:02:05'
Explanation

3725 s = 1 h, 2 min, 5 s.

Constraints

  • Minutes and seconds are 2-digit padded.
  • Works for durations over 24 h.

Topics

Date & Timeduration formatting

Companies

NetflixHotstarSpotify

Hints

Hint 1

divmod(total, 3600) then divmod(rest, 60).

Hint 2

f-string {m:02d} pads.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.