How can I get a formatted date for a UNIX timestamp from the command line
On Mac OS X and BSD:
$ date -r 1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -r 1282368345 +%Y-%m-%d
2010-08-21
with GNU core tools (you have to dig through the info file for that):
$ date -d @1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -d @1282368345 --rfc-3339=date
2010-08-21
With either, add the -u
(standard) option, or pass a TZ=UTC0
environment variable to have the UTC date (TZ=UTC0
defines a timezone called UTC
with offset 0 from UTC while the behaviour for TZ=UTC
(with no offset) is unspecified (though on most systems would refer to a system-defined timezone also called UTC
with offset 0 from UTC)).
This perl one-liner will do it:
$ perl -e 'print scalar localtime $ARGV[0]' 1282367908
Sat Aug 21 09:18:28 2010
After some googling, I found way to do it with the date
command only:
$ date --date "Jan 1, 1970 00:00:00 +0000 + 1282367908 seconds"
Sat Aug 21 09:18:28 MSD 2010