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

前端 未结 12 1598
走了就别回头了
走了就别回头了 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:12

    I haven't tested this but, I think this is how you'd split the string. Followed by multiplying by the appropriate amounts for hours and minutes.

    mytime=’00:20:40.28′
    part1=${mytime%%:*}; rest=${mytime#*:}
    part2=${rest%%:*}; rest=${rest#*:}
    part3=${rest%%:*};
    

提交回复
热议问题