Skip to content

Instantly share code, notes, and snippets.

@andrashann
Last active April 13, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrashann/1bcb53b945c98674e6c2305e9c1f4cee to your computer and use it in GitHub Desktop.
Save andrashann/1bcb53b945c98674e6c2305e9c1f4cee to your computer and use it in GitHub Desktop.
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