Last active
April 13, 2016 14:48
-
-
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
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
# 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