Last active
August 10, 2016 08:42
-
-
Save yohhoy/d4579e55fee85923454636c46a9b0fbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# "hh:mm:ss" to seconds | |
function hms2sec() { | |
hh=$(( 10#`echo $1 | cut -c 1-2` )) | |
mm=$(( 10#`echo $1 | cut -c 4-5` )) | |
ss=$(( 10#`echo $1 | cut -c 7-8` )) | |
echo $(( $hh * 3600 + $mm * 60 + $ss )) | |
} | |
# "hh:mm:ss.nnn" to milliseconds | |
function hmsn2msec() { | |
hh=$(( 10#`echo $1 | cut -c 1-2` )) | |
mm=$(( 10#`echo $1 | cut -c 4-5` )) | |
ss=$(( 10#`echo $1 | cut -c 7-8` )) | |
nnn=$(( 10#`echo $1 | cut -c 10-12` )) | |
echo $(( ($hh * 3600 + $mm * 60 + $ss) * 1000 + $nnn )) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment