Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Two digit year with DateTime?

by hdb (Monsignor)
on Mar 11, 2019 at 13:34 UTC ( #1231122=note: print w/replies, xml ) Need Help??


in reply to Two digit year with DateTime?

DateTime lets you specify a formatter, which is used whenever you print or stringify a DateTime object:

use strict; use warnings; use DateTime; use DateTime::Format::Strptime; my $start_of_week = DateTime->today() ->truncate( to => 'week' ); $start_of_week->set_formatter( DateTime::Format::Strptime->new(pattern + => "%d-%m-%y") ); for ( 0..6 ) { my $teden = $start_of_week->clone()->add( days => $_ ); print "$teden\n"; }

This is useful when you print in many places of your code and want the same format. Remark: installing DateTime::Format::Strptime unleashed a cascade of dependencies on my Perl install...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-05-16 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (63 votes). Check out past polls.

    Notices?