Issue
I am calculating how much time my code is taking in shell script -
date1=$(date +"%s")
# some code here
date2=$(date +"%s")
diff=$(($date2-$date1))
echo "Time Taken - $(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed."
Above script prints out time taken in minutes and seconds. How can I add it for hours as well? Meaning it should print out Time Taken - 0 hours 54 minutes 0 seconds
something like this.
Solution
Try this:
echo "Time Taken - $((diff /60/60)) hours and $(($diff % 60)) minutes and $(($diff % 60)) seconds elapsed."
Answered By - Jens Answer Checked By - Cary Denson (WPSolving Admin)