Convert seconds to hours, minutes, seconds

Use date, converted to UTC:

$ date -d@36 -u +%H:%M:%S
00:00:36
$ date -d@1036 -u +%H:%M:%S
00:17:16
$ date -d@12345 -u +%H:%M:%S
03:25:45

The limitation is the hours will loop at 23, but that doesn’t matter for most use cases where you want a one-liner.

On macOS, run brew install coreutils and replace date with gdate

Leave a Comment