Last active
May 7, 2021 20:59
-
-
Save chrishiestand/829c7b1f8bdf3e98413695b887a5b0a3 to your computer and use it in GitHub Desktop.
Bash script to convert milliseconds since epoch to human readable iso-8601 local time
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
#!/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 -d "@$float" --iso-8601='seconds' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment