Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active August 10, 2016 08:42
Show Gist options
  • Save yohhoy/d4579e55fee85923454636c46a9b0fbd to your computer and use it in GitHub Desktop.
Save yohhoy/d4579e55fee85923454636c46a9b0fbd to your computer and use it in GitHub Desktop.
#!/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