Created
May 10, 2016 00:36
-
-
Save Rudde/4b99049a176de35452a8ee61440aa78e to your computer and use it in GitHub Desktop.
Takes int or float seconds as input will output in format hh:mm:ss.ms where ms is rounded to 3 decimals
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 | |
function padnum { | |
NUM=$1 | |
if [ $(echo "$NUM < 10" | bc) -ne 0 ] | |
then | |
echo 0$NUM | |
else | |
echo $NUM | |
fi | |
} | |
function sec2ts { | |
SEC=$1 | |
HR=$(echo - | awk "{print $SEC / 3600}") | |
HR=${HR%.*} | |
SEC=$(echo - | awk "{print $SEC - ($HR * 3600)}") | |
MIN=$(echo - | awk "{print $SEC / 60}") | |
MIN=${MIN%.*} | |
SEC=$(echo - | awk "{print $SEC - ($MIN * 60)}") | |
SEC=$(printf "%0.3f" $SEC) | |
echo $(padnum $HR):$(padnum $MIN):$(padnum $SEC) | |
} | |
sec2ts $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment