Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: DateTime::Format::Strptime Parsing Seems to have a Problem?

by thanos1983 (Parson)
on Apr 04, 2019 at 15:14 UTC ( #1232151=note: print w/replies, xml ) Need Help??

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 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!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-04-11 18:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found