in reply to Re: Converting dates with Date:Format
in thread Converting dates with Date:Format
Hi 1nickt,
my $datetime = $dt_obj->strftime("%a, %d %b %Y %T EST");
I wouldn't hardcode the timezone into the format string like that, since technically the object's time zone is in DateTime's special "floating" zone, and that's what'd be output if you use %Z (which I personally would still do). To assume a time zone for the input data instead use time_zone=>'EST' in the DateTime::Format::Strptime constructor:
use DateTime::Format::Strptime; my $formatter = DateTime::Format::Strptime->new(pattern => "%F %T",ti +me_zone=>'EST'); my $dt_obj = $formatter->parse_datetime("2008-11-03 19:03:44"); print $dt_obj->strftime("%a, %d %b %Y %T %Z"), "\n"; # to convert to a different zone: $dt_obj->set_time_zone('America/Chicago'); print $dt_obj->strftime("%a, %d %b %Y %T %Z"), "\n"; __END__ Mon, 03 Nov 2008 19:03:44 EST Mon, 03 Nov 2008 18:03:44 CST
Regards,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Converting dates with Date:Format
by 1nickt (Canon) on Jan 10, 2017 at 14:57 UTC | |
by haukex (Archbishop) on Jan 10, 2017 at 15:10 UTC |