Convert Unix timestamp to a date string in Linux

 With GNU's date you can do:
date -d "@$TIMESTAMP"
# date -d @0
Wed Dec 31 19:00:00 EST 1969
On OS X, use date -r.
date -r "$TIMESTAMP"
Alternatively, use strftime(). It's not available directly from the shell, but you can access it via gawk. The %c specifier displays the timestamp in a locale-dependent manner.
echo "$TIMESTAMP" | gawk '{print strftime("%c", $0)}'
# echo 0 | gawk '{print strftime("%c", $0)}'
Wed 31 Dec 1969 07:00:00 PM EST

Comments