Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perlmonks

, Is Date::Manip module will halp to convert GMT time zone to other time zone such as Asia/Dubai, Europe/Budapest?

I had gone through the Date_ConvTZ function, but it is not working for the above format.

&Date_ConvTZ("$date","$from","$to"); for example: the below code will work &Date_ConvTZ("$date","GMT","CST"); but this time zone conversion will not work &Date_ConvTZ("$date","GMT","Asia/Dubai");

Could you please assist to get the proper time for the above said time zone?

Thanks

Replies are listed 'Best First'.
Re: convert GMT to other time zone using Date::Manip
by moritz (Cardinal) on Feb 07, 2011 at 09:03 UTC
Re: convert GMT to other time zone using Date::Manip
by chrestomanci (Priest) on Feb 07, 2011 at 09:14 UTC

    I have used DateTime for date and time related stuff. There is a big collection of modules which will do all sort of date and time related calculations. From their FAQ on Time Zones:

    my $source = DateTime->new( year => 1998, month => 4, day => 7, hour => 13, minute => 55, time_zone => 'America/New_York' ); my $result = $source->clone()->set_time_zone('America/Los_Angeles'); print $source->strftime("%F %r %Z"), " became ", $result->strftime("%F %r %Z"); # Prints: 1998-04-07 01:55:00 PM EDT became 1998-04-07 10:55:00 AM PDT

    From the docs, it looks like Date::Manip is not properly supported anymore.

      In what way is Date::Manip not properly supported anymore? Date::Manip is very much a live, supported module. There were 8 updates last year, and one so far this year. I'm not sure what in the docs make it look like it's not properly supported... but it definitely IS!
      Seconded. I've found that the DateTime family of modules are the only ones which correctly handle timezones. They also explain why things don't always work the way you think at first that they should. I never look at any other perl date/time modules except where I'm using some module which uses them.

        Actually, Date::Manip (starting with version 6.00) handles ALL timezones included in the Olsen database (as well as military timezones, timezone names from Windows, etc.) correctly. This includes historical timezones (those no longer in use). The Date::Manip::TZ documentation covers this in detail as suggested elsewhere in this thread.

        Using the functional interface (i.e. Date_ConvTZ) to do the conversion is NOT recommended. It is strongly recommended that the object-oriented interface be used as it can handle timezones 100% correctly whereas the functional interface is serverly limited. A better solution to the problem in the original message would be:

        $d = new Date::Manip::Date; $d->parse($date); $d->convert($to);