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

Re: Assigning a parsed date to a variable

by AppleFritter (Vicar)
on Mar 30, 2017 at 21:38 UTC ( #1186547=note: print w/replies, xml ) Need Help??


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");

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2020-05-28 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (165 votes). Check out past polls.

    Notices?