pdf Time Left Format Shell function
Par keyphrene, Thursday 15 July 2010 à 06:50 :: Shell Unix :: #35 :: rss
Time Left Format Shell function (Tutorial Shell function)
TimeLeftFormat() { # format = d for day, default is hour sec=$1 format=$2 if [ $format"" = "d" ]; then echo $(($sec/86400))d `TimeLeftFormat $(($sec%86400))` else echo $(($sec/3600))h $((($sec%3600)/60))m $((($sec%3600)%60))s fi } time_left=`TimeLeftFormat 10000` echo $time_left # 2h 46m 40s time_left=`TimeLeftFormat 100000 d` echo $time_left # 1d 3h 46m 40s # Get timestamp with date '+%s' TIME_START=`date '+%s'` TIME_END=`date '+%s'` # Make difference time_left=$((TIME_END - TIME_START)) time_left=`TimeLeftFormat $time_left` echo $time_left
TAGS: Tutorial Shell function time date format

Comments
No comment for this moment.
Add a comment