Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Created March 7, 2018 22:57
Show Gist options
  • Save jfeilbach/22330779ad4120d3f96054eda95bdfc3 to your computer and use it in GitHub Desktop.
Save jfeilbach/22330779ad4120d3f96054eda95bdfc3 to your computer and use it in GitHub Desktop.
convert bash seconds to human readable hours minutes seconds
displaytime () {
local T=$SECONDS
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
[[ $D > 0 ]] && printf '%d days ' $D
[[ $H > 0 ]] && printf '%d hours ' $H
[[ $M > 0 ]] && printf '%d minutes ' $M
[[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and '
printf '%d seconds\n' $S
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment