Simple way to convert HH:MM:SS (hours:minutes:seconds.split seconds) to seconds

前端 未结 12 1604
走了就别回头了
走了就别回头了 2021-01-31 16:40

What\'s an easy way to convert 00:20:40.28 (HH:MM:SS) to seconds with a Bash script?

Split seconds can be cut out, it’s not essential.

12条回答
  •  难免孤独
    2021-01-31 17:27

    You can convert minutes to hour, seconds, or minutes with bc command.

    By example:

    How many minutes for 1000 sec ?

    $ echo 'obase=60;1000' | bc
    02 00
    

    then -> 2 min

    How much hour for 375 min ?

    $ echo 'obase=60;375'| bc
    06 15
    

    then -> 06h15

    How days for 56 hours?

    $ echo 'obase=24;56' | bc
    02 08
    

    then 02 days and 08 hours

    bc with obase is extra!

提交回复
热议问题