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.
To convert hh:mm:ss to seconds:Convert the hours to seconds, by multiplying by 60 twice. Convert the minutes to seconds by multiplying by 60 .
To convert hours and minutes to minutes, you have to multiply the hh:mm value by 1440 (which is 24 [number of hours in the day] multiplied by 60 [number of minutes in an hour]), AND make sure you set the formatting correctly for the both the hh:mm cells and the resulting minute cells.
Try awk
. As a bonus, you can keep the split seconds.
echo "00:20:40.25" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With