Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Easily print unix epoch timestamp in human-readable form on the command line
# take a Unix timestamp and print it in human-readable form;
# works both on Linux and OS X.
#
# copy this to your .bash_profile, then you can use it as:
# from_unixtime 1460558700
# returns: Wed Apr 13 16:45:00 CEST 2016
from_unixtime() {
thedate="$1"
thedate=${thedate:0:10}
# the command above is a simple method to remove milliseconds.
# it works until 2286-11-20 17:46:40, after which unix timestamps
# will have 11 digits.
if [[ "$(uname)" == "Darwin" ]]; then
date -r $thedate
else
date -d @$thedate
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment