I have a UNIX timestamp and I'd like to get a formatted date (like the output of date
) corresponding to that timestamp.
My attempts so far:
$ date +%s
1282367908
$ date -d 1282367908
date: invalid date `1282367908'
$ date -d +1282367908
date: invalid date `+1282367908'
$ date +%s -d +1282367908
date: invalid date `+1282367908'
I'd like to be able to get output like:
$ TZ=UTC somecommand 1282368345
Sat Aug 21 05:25:45 UTC 2010
Best Answer
On Mac OS X and BSD:
with GNU core tools (you have to dig through the info file for that):
With either, add the
-u
(standard) option, or pass aTZ=UTC0
environment variable to have the UTC date (TZ=UTC0
defines a timezone calledUTC
with offset 0 from UTC while the behaviour forTZ=UTC
(with no offset) is unspecified (though on most systems would refer to a system-defined timezone also calledUTC
with offset 0 from UTC)).