I have an interval, in seconds with a decimal, that I'd like to display in human-readable (H:MM:SS.SSS) format. For example, 16633.284 should be displayed as 4:37:13.284. All these times are under 24 hours, but if they were over it'd still just be hours.
A few more examples:
0 → 0:00:00.000
60.394 → 0:01:00.394
8944.77 → 2:29:04.770
Note it's fixed-width for under 10 hours. Of course, that's fairly easily done with printf
.
I'm posting my solution as an answer, but it feels like there must be a better way to do it, so I'm asking: what are the other ways? I'm open to ways that are bashisms, zshisms, etc.
Note: This is related to Displaying seconds as days/hours/mins/seconds? but those approaches all don't work because arithmetic in bash is integer-only.
zsh
(though many shells have an equivalent):TIMEFMT='%*E'; time sleep 60.394
. Sorry. – Stéphane Chazelas May 20 '17 at 07:17