This tool converts a plain number of seconds into a readable phrase such as
2 hours, 34 minutes, 56 seconds. It is handy for displaying job runtimes,
video lengths, cache ages, or any elapsed-time value that would otherwise be an
opaque integer.
How it works
The total is divided down through a fixed table of units, from largest to smallest, taking the whole-number quotient at each step and carrying the remainder forward:
years = floor(total / 31557600) ; 365.25 days
months = floor(rem / 2629800) ; year / 12
weeks = floor(rem / 604800) ; optional
days = floor(rem / 86400)
hours = floor(rem / 3600)
minutes = floor(rem / 60)
seconds = rem
Only units with a non-zero value are shown, and the list is truncated to the maximum number of parts you choose. Because the higher units use average lengths (365.25 days per year), the result stays accurate over long spans without anchoring to a calendar.
Example and tips
9296 seconds becomes 2 hours, 34 minutes, 56 seconds, or 2 hours, 34 minutes
if you cap the output at two parts. For a friendly summary on a dashboard, keep
the maximum at 2 or 3 parts; for an exact breakdown, raise it to 7. The minus
sign on negative inputs lets you reuse the same tool for both countdowns and
elapsed time.