Bash script: difference in minutes between two times

前端 未结 7 1632
不思量自难忘°
不思量自难忘° 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:18

    @Dorian
    If you just want to know how long a program took to run: time, man, man time!

    Trivial example:

    jonathan@Odin:~$ time sleep 1
    
    real    0m1.001s
    user    0m0.000s
    sys     0m0.000s
    

    OK, it doesn't give the result in seconds, but you can make it do so with a format string, or more simply with the POSIX compliance option:

    jonathan@Odin:~$ time -p sleep 20
    real 20.00
    user 0.00
    sys 0.00
    

提交回复
热议问题