Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: formatting datetime with strftime

by GeneralElektrix (Acolyte)
on Jul 22, 2013 at 15:40 UTC ( #1045680=note: print w/ replies, xml ) Need Help??


in reply to formatting datetime with strftime

#!perl -w use strict; use DateTime::Format::CLDR; my $datetimestring = "4/5/13 16:09"; my $cldr1 = new DateTime::Format::CLDR( pattern => 'M/d/yy HH:mm', ); my $dt1 = $cldr1->parse_datetime($datetimestring); print $cldr1->format_datetime($dt1), "\n"; my $cldr2 = new DateTime::Format::CLDR( pattern => 'MMMM dd yyyy HH:mm:ss', locale => 'en_US', time_zone => 'GMT', ); print $cldr2->format_datetime($dt1), " GMT\n";


Comment on Re: formatting datetime with strftime
Download Code
Re^2: formatting datetime with strftime
by GeneralElektrix (Acolyte) on Jul 22, 2013 at 18:08 UTC
    I think I improved on this version of the code. Let's suppose the original time is in the 'America/New-York' time zone and you want it in GMT, here's the new recipe:
    #!perl -w use strict; use DateTime::Format::CLDR; my $datetimestring = "4/5/13 16:09"; my $cldr1 = new DateTime::Format::CLDR( pattern => 'M/d/yy HH:mm', time_zone => 'America/New_York', ); my $dt1 = $cldr1->parse_datetime($datetimestring); print $cldr1->format_datetime($dt1), "\n"; my $cldr2 = new DateTime::Format::CLDR( pattern => 'MMMM dd yyyy HH:mm:ss', locale => 'en_US', time_zone => 'America/New_York', ); $dt1->set_time_zone('GMT'); print $cldr2->format_datetime($dt1), " GMT\n";
    Result:
    4/5/13 16:09 April 05 2013 20:09:00 GMT

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-07-13 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls