in reply to Convert epoch seconds to date

There are several perl modules that can do this for you. My favorite for this task is Time::CTime (check out the strftime function). This task is also real easy to write yourself using perl's built-in localtime function.

Of course, this all assumes that your Epoch is Jan 1, 1970 (which is a pretty safe bet) If that isn't your epoch you'll need to do more conversion first.

Replies are listed 'Best First'.
Re: Re: Convert epoch seconds to date
by slayven (Pilgrim) on Mar 19, 2001 at 19:47 UTC
    @time = (localtime())[3..5]; $time[1]++; $time[2] += 1900; print join ('/', @time);
    can't get it shorter :(

      Update: I thought I was in a different thread so much of this is incorrect. My apologies to slayven. ):

      Note that this does d-m-yyyy which isn't what was asked for (the order is wrong and you don't pad with zeros).

      use mapcar; print join '-', mapcar {sprintf "%02d",pop()+pop} [(localtime())[5,4,3]],[1900,1,0];
      Is my contribution (which does yyyy-mm-dd since that is simply a better format).

      See mapcar -- map for more than one list for one needed part.

              - tye (but my friends call me "Tye")
Re: This one is easy
by Anonymous Monk on Jul 20, 2003 at 22:15 UTC
    my $epoch_seconds = "?";
    my $date = scalar localtime($epoch_seconds);