Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm having some problems (could be the sun, could be the beer), getting my head round converting the unix epoch day (i.e. as appears in /etc/shadow) to epoch seconds so I can do some calculations. . .

Can anybody point me in the right direction....

Regards

Rich

Replies are listed 'Best First'.
Re: unix epoch date
by shemp (Deacon) on Aug 08, 2003 at 16:09 UTC
    Check out the built in localtime(). It takes an epoch seconds arguement, and returns an array consisting of various date / time parts. Depending on your calculations, the breakdown returned by localtime() can make the calculations easy.
      Yer, I've been working through that today, however I can't work out how I can translate 12272 as being today, if I user localtime I make today 1062975600 !!!
        A day is 24 hours with 60 minutes with 60 seconds each.
        perl -le 'print time() / (24*60*60)'
        Alternatively,
        perl -le 'print scalar localtime( 12272 * 24*60*60 )' perl -le 'print scalar gmtime( 12272 * 24*60*60 )'

        --
        [ e d @ h a l l e y . c c ]

        Where do you get 12272 from? is there some code snippet that is causing trouble, i need to know more of whats going on.
        sorry I meant if I use localtime(). . .
Re: unix epoch date
by TomDLux (Vicar) on Aug 08, 2003 at 22:41 UTC