Last Updated: June 7, 2026
A duration like 3661 seconds reads better the way a clock shows it: 1 hour, 1 minute, 1 second. The conversion relies on two fixed facts. One hour is 3600 seconds, and one minute is 60 seconds.
To split one number into three parts, work from the largest unit down. Find how many full hours fit inside the total, then how many full minutes fit inside what is left, and whatever remains is the seconds.
Two operations drive this. Integer division (/) tells you how many whole units fit, and modulo (%) tells you what is left over after removing them. Together they peel off one unit at a time.
totalSeconds is a non-negative integer → There are no negative inputs to handle, so the result values are always zero or positive. Plain integer division and modulo behave predictably for non-negative numbers.Integer division totalSeconds / 3600 counts the whole hours and discards the remainder. The leftover seconds are totalSeconds % 3600. Applying the same pair of operations with 60 splits that leftover into minutes and seconds.
The pattern is to divide to peel off the largest unit, carry the remainder forward with modulo, and repeat with the next smaller unit. The final remainder is the seconds.
hours = totalSeconds / 3600 using integer division. This counts the whole hours.remaining = totalSeconds % 3600. These are the seconds left after removing the full hours.minutes = remaining / 60. This counts the whole minutes in the leftover.seconds = remaining % 60. These are the seconds left after removing the full minutes.[hours, minutes, seconds].Start with totalSeconds = 3661.
Step 1: hours = 3661 / 3600 = 1. One full hour fits inside 3661 seconds.
Step 2: remaining = 3661 % 3600 = 61. After removing 3600 seconds, 61 seconds remain.
Step 3: minutes = 61 / 60 = 1. One full minute fits inside the 61 leftover seconds.
Step 4: seconds = 61 % 60 = 1. After removing 60 seconds, 1 second remains.
The result is [1, 1, 1], which reads as 1 hour, 1 minute, 1 second.