2008-01-22

Perl: Convert epoch seconds to readable time

As a system administrator, It's not uncommon to run across time stamps represented in Epoch Seconds, that is basically the number of seconds that have passed since the start of Jan 1, 1970 UTC.  I most often run across these time stamps stored in database records, but you'll see it elsewhere, too.   An Epoch time stamp for any fairly recent date looks like a huge string of digits, such as "1201017672".  Obviously, time stamps closer to the beginning of the 1970 Epoch are significantly smaller.

To make some kind of sense out of that stamp, you can use perl's localtime() function right from the UNIX command-line.
$ perl -e 'print scalar localtime('1201017672'); print "\n";'
Tue Jan 22 10:01:12 2008

blog comments powered by Disqus