Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Convert GMT date and time to local time

by haukex (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-11-25 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (355 votes). Check out past polls.

    Notices?