Convert time Seconds to Hours-Minutes-Seconds format – Shell Scripting – Video

I came across the situation, when i provide seconds it should print values in Hours, Minutes and Seconds. Directly How many seconds equals to how many Hours/Minutes/Seconds. We are going to see on small shell script which can calculate and do it for us. convert time seconds to Hours-Minutes-Seconds.

Convert time seconds to H:M:S

It is a simple bash script which will convert seconds to Hours:Minutes:Seconds format. convert time.

First method of script is below, i observed an issue while running same shell script in Ubuntu OS is not working Upended with second method using bc command

##Author: Ankam Ravi Kumar
##Date: 10th July 2017
##Convert Seconds to Hours:Minutes:Seconds Format Using this script
## Starting of Script ##

[ -z  ] && echo "Usage: $(basename $0) <seconds>" && exit||secs=
 local S=
printf "%dh:%dm:%ds\n" $h $m $s

_hms ${secs}

## END Of Script##

Convert Time Seconds to Hours Minutes Seconds Shell Script

Please do comment your feedback is very important to us

## Ankam Ravi Kumar
##Date: 11th July 2017
##Seconds to Hours:Minutes:Seconds Format Using this script
if [ $1 -ge 1 ]; then
H=`echo $S / 3600 | bc`
M=`echo $S % 3600 / 60 | bc`
S=`echo $S % 60 | bc`
echo "H: $H M: $M S: $S"
echo "Usage: sh <seconds>"

Output of this convert Seconds shell script is below

# sh 8000
H: 2 M: 13 S: 20

Related Articles

Debug Shell Script Easily identify errors

What is Shell scripting Very Basic to Learn

Logical Volume Manager Step by Step Guide

Thanks for your wonderful Support and Encouragement