Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

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

Help for this page

Select Code to Download


  1. or download this
    use Time::Piece qw(localtime);
    use Time::Seconds qw(ONE_DAY);
    ...
    print "Today: ", $t->ymd(),"\n";
    print "Yesterday: ", $yesterday->ymd(),"\n";
    print "Tomorrow: ", $tomorrow->ymd(),"\n";
    
  2. or download this
    my $t = localtime->strptime(localtime->ymd(), '%Y-%m-%d');
    my $yesterday = $t - ( 0.5 * ONE_DAY() );
    ...
    print "Today: ", $t->ymd(),"\n";
    print "Yesterday: ", $yesterday->ymd(),"\n";
    print "Tomorrow: ", $tomorrow->ymd(),"\n";
    
  3. or download this
    my $t = localtime->strptime('2013-03-11', '%Y-%m-%d');
    my $yesterday = $t - ONE_DAY();
    ...
    Today: 2013-03-11
    Yesterday: 2013-03-09
    Tomorrow: 2013-03-12
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044913]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2017-02-26 02:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (371 votes). Check out past polls.