From RootdevWiki

Jump to: navigation, search

Fun with Time

Changing seconds since epoch to localtime

Sounds easy huh? Have you ever actually read the 'date' man page and tried to work out how to do it?

I'll save you the bother - there's lots of complicated ways of doing it which all have varying degrees of success, especially when you bring timezones into the equation, but as far as I can see this undocumented feature does exactly what you want:

$ date --date=@1173423099
Fri Mar  9 17:51:39 2007

NB - does not work on FC4 date Version 5.2.1. Works fine on 5.96 on Ubuntu.

Epoch to localtime with perl

You can also do it with this nifty perl one liner:

$ perl -e "print scalar(localtime(1173423099))"
Fri Mar  9 17:51:39 2007

Or with a little more sophistication:

$ perl -e 'use POSIX qw(strftime); print \
scalar(strftime("%Y-%m-%d %H:%M:%S", localtime(1175138442)))."\n"'
2007-03-29 13:20:42