http://qs321.pair.com?node_id=1232151


in reply to DateTime::Format::Strptime Parsing Seems to have a Problem?

Hello ozboomer,

It looks that fellow Monks have already answered your question. Just for fun here is an alternative solution using Date::Manip.

#!/usr/bin/perl use strict; use warnings; use Date::Manip; use feature 'say'; sub getDate { my $tz = new Date::Manip::TZ; return $tz->convert_from_local(ParseDate(shift), 'Australia/Victor +ia'); } sub getDateFormat { my ($date, $from, $to) = @_; return UnixDate(Date_ConvTZ(ParseDate($date), $from, $to), '%d/%m/ +%Y %r'); } my @dates = ( "now", "03/18/2019 03:15:00", "03/18/2019 03:15:00 am", "03/18/2019 03:15:00 pm", ); foreach my $date (@dates) { my ( $err, $date, $offset, $isdst, $abbrev ) = getDate($date); say "Err: $err" if $err; say "Date: " . join(":", @$date); # say "@$date[2]/@$date[1]/@$date[0] @$date[3]:@$date[4]:@$date[5] +"; # say "Offset: " . join(":", @$offset); # say "Isdst: $isdst"; # say "Abbrev: $abbrev"; say getDateFormat($date,"CST", "AEDT"); } __END__ $ perl test.pl Date: 2019:4:5:2:3:8 05/04/2019 03:00:00 AM Date: 2019:3:18:13:15:0 18/03/2019 03:00:00 AM Date: 2019:3:18:13:15:0 18/03/2019 03:00:00 AM Date: 2019:3:19:1:15:0 19/03/2019 03:00:00 AM

On the solution provided above I have two different functions. One is simply converting the time from the local timezone getDate (read more Date::Manip::TZ) and the other is converting from the timezone provided to the function getDateFormat (read more for timezone Date::Manip::Zones). The first function unfortunately it returns the date already formatted so there the format is fixed. The second it returns to your desired format.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!