Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Convert GMT date and time to local time

by haukex (Abbot)
on Sep 13, 2017 at 09:33 UTC ( #1199283=note: print w/replies, xml ) Need Help??

in reply to Convert GMT date and time to local time

Does it have to be Date::Manip? I prefer DateTime, it has excellent time zone handling and everything else regarding date/time handling, also via add-ons like for example DateTime::Format::Strptime.

use warnings; use strict; use DateTime; use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new(on_error=>'croak', pattern => '%Y-%m-%d-%H:%M:%S %Z'); my $datestr = "2016-07-30-15:30:00 GMT"; my $dt = $strp->parse_datetime($datestr); print $dt->strftime('%Y-%m-%d-%H:%M:%S %Z'), "\n"; $dt->set_time_zone('America/Los_Angeles'); print $dt->strftime('%Y-%m-%d-%H:%M:%S %Z'), "\n"; __END__ 2016-07-30-15:30:00 UTC 2016-07-30-08:30:00 PDT

Replies are listed 'Best First'.
Re^2: Convert GMT date and time to local time
by Anonymous Monk on Sep 13, 2017 at 10:11 UTC
    Thanks! It does the job as I needed. The Date::Manip documentation was a nightmare for me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199283]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2018-06-20 23:31 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.