use strict; use warnings; #use diagnostics; use DateTime; use DateTime::Format::Strptime; our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); my $dtnow = DateTime->now(time_zone => $LocalTZ); # Current *local* time printf("\$dtnow: !%s!\n", $dtnow); my $lo = "18/03/2019 10:12:53 am"; # Always works my $hi = "24/03/2019 3:15:00 pm"; # Does not work... the format I need to use # my $hi = "24/03/2019 03:15:00 pm"; # Does not work # my $hi = "24/03/2019 3:15:00 pm"; # Does not work # my $hi = "24/03/2019 15:15:00 pm"; # Works but 15hrs with 'pm' is silly # my $hi = "24/03/2019 15:15:00"; # Works my $dmy_fmt = DateTime::Format::Strptime->new( # Let DateTime use 'dd/mm/yyyy' pattern => '%d/%m/%Y %H:%M:%S %p', # pattern => '%d/%m/%Y %H:%M:%S', # Use this when no 'am/pm' in the date string time_zone => 'Australia/Victoria', # time_zone => 'local', ); my $lodt = $dmy_fmt->parse_datetime($lo); printf(" \$lodt: !%s!\n", $lodt); my $hidt = $dmy_fmt->parse_datetime($hi); printf(" \$hidt: !%s!\n", $hidt);