Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

TIME::LOCAL from within KSH

by g_speran (Scribe)
on May 19, 2007 at 02:03 UTC ( [id://616292]=perlquestion: print w/replies, xml ) Need Help??

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

Hello all, Sorry if this is easy but I just can not figure it out. I am modifying a KSH script and within it i need to get an epoch time. So I have been trying the following with no result. If you can offer some guidance or sate if it can even be done, I would appreciate it.
epoch_time=`perl -mTIME::LOCAL -e"print timelocal(58,41,21,18,5,2007)" +`
so I am looking to use epoch_time later in the ksh script thanks Gary

Replies are listed 'Best First'.
Re: TIME::LOCAL from within KSH
by AltBlue (Chaplain) on May 19, 2007 at 03:02 UTC
    An error message would have been useful here, but for starters let's guess you meant Time::Local (case sensitive) and -M (importing timelocal).
    e.g.: perl -MTime::Local -le 'print timelocal(...)'

    Better yet, rather than calling perl for such tiny operations maybe you should read date(1) man page (pay attention to -d parameter).


      What version of "date(1)" are you talking about? My version (MacOSX/darwin, based on bsd) doesn't have a "-d" option at all, and on a freebsd machine, "-d" means "set the kernel's value for daylight savings time". (Looks like the Solaris 5.8's "date" didn't have "-d" either, and on a linux box, "-d STRING" doesn't seem to report seconds since epoch, but  date +%s does.)

      Just curious...

        What version of "date(1)" are you talking about?

        Sorry, OP didn't mention anything about his/her env.

        "-d STRING" doesn't seem to report seconds since epoch, but date +%s does

        "-d STRING" will be used for passing custom time, otherwise you'll be formatting the current time ;-)


        $ date -d '1987-12-18 12:13:14' -u '+%s' 566827994 $ date -d '1987-12-18' -u '+%s' 566784000


Re: TIME::LOCAL from within KSH
by TOD (Friar) on May 19, 2007 at 11:56 UTC
    as far as i know the package is called Time::Local.

    masses are the opiate for religion.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://616292]
Approved by graff
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-07-14 10:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.