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 thoughts on “Converting time since the epoch to a human readable string”

  1. awk can do it for you too:

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

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *