Bash script: difference in minutes between two times

前端 未结 7 1615
不思量自难忘°
不思量自难忘° 2020-12-31 07:55

I have two time strings; eg. \"09:11\" and \"17:22\" on the same day (format is hh:mm). How do I calculate the time difference in minutes between these two?

Can the

7条回答
  •  春和景丽
    2020-12-31 08:07

    Here is how I did it:

    START=$(date +%s);
    sleep 1; # Your stuff
    END=$(date +%s);
    echo $((END-START)) | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}'
    

    Really simple, take the number of seconds at the start, then take the number of seconds at the end, and print the difference in minutes:seconds.

提交回复
热议问题