Skip to content

Instantly share code, notes, and snippets.

@chrishiestand
Last active May 7, 2021 20:59
Show Gist options
  • Save chrishiestand/829c7b1f8bdf3e98413695b887a5b0a3 to your computer and use it in GitHub Desktop.
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
#!/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