Created
May 7, 2021 20:59
-
-
Save chrishiestand/acb51c9feee24057e365079e5bd5b2c0 to your computer and use it in GitHub Desktop.
Bash script to convert milliseconds since epoch to human readable iso-8601 utc time
This file contains 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
#!/usr/bin/env bash | |
millis=${1-} | |
if [ -z "$millis" ]; then | |
script="${0##*/}" | |
echo "usage: $script milliseconds-since-epoch" | |
echo "example: $script 1620418406902" | |
exit 1 | |
fi | |
float=$(echo "scale=3; $millis / 1000" | bc) | |
command="date" | |
# add for MacOS portability, requires coreutils to be installed via homebrew | |
if [ ! -z "$(which gdate)" ]; then | |
command="gdate" | |
fi | |
$command -u -d "@$float" --iso-8601='seconds' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment