Skip to content

Instantly share code, notes, and snippets.

@broilogabriel
Created November 26, 2020 15:48
Show Gist options
  • Save broilogabriel/05ab5cc09f39fe818a85d9302646aeec to your computer and use it in GitHub Desktop.
Save broilogabriel/05ab5cc09f39fe818a85d9302646aeec to your computer and use it in GitHub Desktop.
Simple function to convert timestamp or timeuuid to human readable date
#!/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