Converting time since the epoch to a human readable string

I was parsing some Netbackup logs today, and needed a way to convert the time since the epoch into a human readable string. A while back I read about the various forms of input that can be passed to the GNU date’s “-d” option, one of these being the time since the epoch:

$ date -d @1263408025
Wed Jan 13 13:40:25 EST 2010

This solved my issue, though unfortunately it’s not super portable. Food for thought.

5 Comments

redtigra  on April 16th, 2010

$perl -e ‘print scalar localtime (1263408025), “\n”‘
Wed Jan 13 19:40:25 2010

Frank  on April 16th, 2010

awk can do it for you too:

awk ‘{ printf(“%s\n”,strftime(“%a %d %b %Y %T %Z”,’1263408025′)) }’

justintime  on April 16th, 2010

Not as pretty, but more portable:
perl -e ‘print localtime(1263408025).”\n”‘

BrianDKing  on April 16th, 2010

For netbackup logs, we often use this:

bperror|perl -ane ‘print localtime($F[0]) . $_’

It’s a little more portable than GNU date, as perl is found on most modern UNIX systems, but not so often on windows.

grokus  on May 3rd, 2010

On NetBSD
$ date -r 1263408025
Wed Jan 13 13:40:25 EST 2010

Leave a Comment