http://www.perlmonks.org?node_id=1186547


in reply to Assigning a parsed date to a variable

Have you considered turning to CPAN instead of rolling your own regular expressions to parse dates/times? My immediate instinct was to reach for e.g. Time::ParseDate, or one of the DateTime::Format::* family.

DateTime itself should then be able to format the result in any way you want. For instance:

#!/usr/bin/perl use Modern::Perl '2015'; use DateTime; use Time::ParseDate; my $adate = "2017-01-29 11:30:07.370"; my $epoch_seconds = parsedate($adate, ZONE => "UTC"); my $dt = DateTime->from_epoch(epoch => $epoch_seconds); say $dt->strftime("%m-%d-%Y %H:%M");