Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What's "Better" DateTime or localtime?

by runrig (Abbot)
on Jul 11, 2013 at 17:22 UTC ( #1043792=note: print w/ replies, xml ) Need Help??


in reply to What's "Better" DateTime or localtime?

For simple things, I like Time::Piece myself...no need to add one to the month or 1900 to the year. For more complicated things, I'll use DateTime.

Update: Also, I agree w/jeffa ... (strptime/strftime)++ !!


Comment on Re: What's "Better" DateTime or localtime?
Re^2: What's "Better" DateTime or localtime?
by mmartin (Monk) on Jul 11, 2013 at 17:39 UTC
    Hey runrig, thanks for the quick reply!

    That's cool, I haven't seen that one before... I just checked its Perldoc out (http://perldoc.perl.org/Time/Piece.html) and
    it seems simple enough. Might be good to give that a try...


    Hummm.... Just thought of something as I'm writing this.
    Once I'm finished with my script I will be porting it to a windows executable using something like "pp" or "CavaPackager". Currently
    I'm writing the script on MY laptop which is linux.

    So what I was just thinking now is that since the use of localtime does NOT require you to include a Module to use it, would
    it be better to use that one in that case? Since things like CavaPackager will include the needed Modules in order to execute the
    script? Does that make sense?

    Again, thanks for the reply, much appreciated.

    Thanks Again,
    Matt

Re^2: What's "Better" DateTime or localtime?
by mmartin (Monk) on Jul 11, 2013 at 17:46 UTC
    Humm... Looking at the Synopsis of the Time::Piece Module again I noticed it also uses localtime.

    So since it uses "localtime" does that mean when you include the Module, that it actually modifies what
    localtime will output..?


    Thanks Again,
    Matt

      So since it uses "localtime" does that mean when you include the Module, that it actually modifies what localtime will output?

      By default, yes, it exports and overrides localtime. If you don't want to do that, you can import nothing:

      use Time::Piece qw();
      If I do want to override localtime, I will usually explicitly import it:
      use Time::Piece qw(localtime);
        Hey runrig, thanks again for the reply!

        Ahh haa, Ok that makes sense... Cool, thanks for the info!


        Thanks Again,
        Matt

        After playing around with the Time::Piece Module for a bit I think I'm going to use that instead as you suggested.

        It seems like there's a ton more Methods available for it including this one which is cool --> $date->mdy("/").
        It looks like there is about, like 50-60 methods available for the Module so it seems pretty flexible...

        I like it!

        Thanks Again,
        Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043792]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-09-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls