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

Re^2: How to convert time from one time zone to another

by Celada (Monk)
on Dec 19, 2005 at 21:32 UTC ( #517902=note: print w/replies, xml ) Need Help??


in reply to Re: How to convert time from one time zone to another
in thread How to convert time from one time zone to another

You should probably use the named timezones instead of numeric pseudo timezones as you have. For example, US/Eastern for New York. Your example will show an incorrect time for New York in the summer.

Replies are listed 'Best First'.
Re^3: How to convert time from one time zone to another
by robin (Chaplain) on Dec 19, 2005 at 21:51 UTC
    You have a good point. There is a frustrating trade-off, in that “numeric pseudo-timezones” are pretty portable. The named (Olson) timezones still won’t work everywhere, unfortunately, although the situation is improving.

    If portability is not a concern, and the Olson names work on your system, you should definitely use them. If you need to be portable and to deal with all the intricacies of daylight saving time, you probably have to use DateTime with DateTime::TimeZone (which parses the Olson database) and install a copy of the Olson database if your system doesn't already have it.

    (Unless there's a better way that I don't know about?)

    Update: Actually I think the module is distributed with a pre-parsed copy of the database, so at least you don't have to worry about that. It's still a lumbering behemoth whose documentation is rather confusing, at least to me; but it should give accurate results at least.

Re^3: How to convert time from one time zone to another
by ww (Archbishop) on Apr 02, 2012 at 15:12 UTC
    Actually I don't think the statement (that parent's code will produce an incorrect time during DST) is correct but neither do I think Robin's surmise that the code in Re: How to convert time from one time zone to another will "work on Windows" is universally correct. Under Windows7:
    #!/usr/bin/perl use 5.014; # convert TZ say "\$ENV{TZ}: $ENV{TZ}"; # var had to be manually added on stock + W7 { local $ENV{TZ} = "EST+05"; say "In New York, it is " . localtime(); } { local $ENV{TZ} = "IST-05:30"; # does not return c +orrect time on W7 say "In Mumbai, it is " . localtime(); # but, rather, same + as NY localtime }

    outputs:

    $ENV{TZ}: EST5EDT # TZ is set but this does + # not appear to be defaul +t (for Win7) In New York, it is Mon Apr 2 10:41:23 2012 # correct In Mumbai, it is Mon Apr 2 10:41:23 2012 #obviously wrong

    But this may be the result of a misconception on my part about 'doze ENV and its vars.
        Anyone care to explicate?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2022-10-07 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?