Pages

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

4 comments:

  1. Yes, you could. But why not:

    $ newlisp -e '(date 1201017672)'
    "Tue Jan 22 16:01:12 2008"
    $

    ReplyDelete
  2. Ah, sweet simplicity. I really wish I had more time to devote to NewLISP.

    I chose perl for this particular one because it comes with most operating systems, although I have NewLISP installed on every one of the systems I run personally. They won't let me install it on the enterprise environment at work.

    ReplyDelete
  3. Yeah, I know... they make us use Windows too... :) You could always use the Lambdalator... (http://lambdalator.nfshost.com/) - for frustrated newLISP users everywhere!

    Wonder if newLISP could run from a memory stick...? :)

    I hope you get round to some more newLISP posts one day!

    ReplyDelete
  4. Actually my job involves working on hundreds upon hundreds of various UNIX systems. They won't let me install newLISP on production servers.

    ReplyDelete