Comment #461
Anonymous wrote
the following reply to
https://scripter.co/convert-seconds-to-human-time/:
God damn formatting got the best of me, here's how you split seconds into mod-60 units:
```elisp
(defun secs-to-units (timef)
"Split the seconds in the integer or float `timef' into a list of dhms"
(let* ((time (floor timef))
(frac (- timef time))
(hrs (% (/ time (* 60 60)) 24))
(mins (% (/ time 60) 60))
(secs (+ (% time 60) frac))
(days (/ time (* 60 60 24))))
`(,days ,hrs ,mins ,secs)))
(defun fmt-secs (time)
"Format seconds."
(pcase-let ((`(,d ,h ,m ,s) (secs-to-units time)))
(format "%dd %dh %dm %.2fs" d h m s)))
```
Reply to this comment