Skip to content

Instantly share code, notes, and snippets.

@MaxChinni
Last active September 15, 2015 11:25
Show Gist options
  • Save MaxChinni/8824092 to your computer and use it in GitHub Desktop.
Save MaxChinni/8824092 to your computer and use it in GitHub Desktop.
bash number of seconds to human readable time
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage:" >&2
echo " $(basename $0) <sec>" >&2
exit 1
fi
function secToTime() {
local s=$1
local hh=$(($s / 60 / 60))
local mm=$(( ($s - $hh * 60 * 60) / 60 ))
local ss=$(( $s % 60 ))
printf "%02d:%02d:%02d" "$hh" "$mm" "$ss"
}
secToTime $1
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment