How can I convert seconds to hours, minutes and seconds?
show_time() { ????? } show_time 36 # 00:00:36 show_time 1036 # 00:17:26 show_time 91925 # 25:32:05
To convert seconds to HH:MM:SS :Multiply the seconds by 1000 to get milliseconds.
There are 3,600 seconds in 1 hour. The easiest way to convert seconds to hours is to divide the number of seconds by 3,600.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With