Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Convert GMT date and time to local time

by haukex (Archbishop)
on Sep 13, 2017 at 09:33 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1199283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found