Created
November 26, 2020 15:48
-
-
Save broilogabriel/05ab5cc09f39fe818a85d9302646aeec to your computer and use it in GitHub Desktop.
Simple function to convert timestamp or timeuuid to human readable date
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 epoch() { | |
number='^[0-9]{13}$' | |
uuid='^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$' | |
if [[ "$1" =~ $number ]]; then | |
TS=$1 | |
elif [[ "$1" =~ $uuid ]]; then | |
strdate="$(uuid -d $1 | grep 'time:' | awk '{print $3,$4}' | cut -c1-26)" | |
TS=$(($(date -d "$strdate" +"%s%N") / 1000000)) | |
else | |
echo "Invalid parameter will print now" | |
TS="$(date +%s%N | cut -b1-13)" | |
fi | |
s=${TS%???} | |
ms=${TS#"$s"} | |
echo "millis: $TS - $(date -d @$s +"%F %T.$ms UTC")" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment