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

Re: Two digit year with DateTime?

by hdb (Monsignor)
on Mar 11, 2019 at 13:34 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found