Answers for "how to calculate duration of time in shell script"

0

how to calculate duration of time in shell script

#!/usr/bin/env bash
# 1 method
SECONDS=0
# do some work
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."

# 2 method
string1="10:33:56"
string2="10:36:10"
StartDate=$(date -u -d "$string1" +"%s")
FinalDate=$(date -u -d "$string2" +"%s")
date -u -d "0 $FinalDate sec - $StartDate sec" +"%H:%M:%S"

# 3 method
START=$(date +%s);
sleep 1; # Your stuff
END=$(date +%s);
echo $((END-START)) | awk '{print int($1/60)":"int($1%60)}'
Posted by: Guest on April-24-2022

Code answers related to "how to calculate duration of time in shell script"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language