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

Fellow Monks:

I would like to know if there is a perl module or subroutine in a given modules that does the following:
Given GMT time and the offset from GMT time in 24 hour format, I need to be able to input the date and time; hours, minutes, date (year,month day), and hour offset such as -5 hours and have it converted to the correct time and date.
Example:
Input: 01:50 01/18/2005 offset -5 hours
Output: 20:50 01/17/2005
Perhaps the code and hypthetical subroutine would look something like this:
#GMT time,date my($Gyr,$Gm,$Gd,$Gh,$Gm,$offset)=(2006,1,8,1,34,-5); #subroutine converts to local time, date #from GMT w/ specified offset #where convertTZ is "hypothetical subroutine my($y,$m,$d,$h,$m)=&convertTZ($Gyr,$Gm,$Gd,$Gh,$Gm,$offset);
I am still continuing to search through CPAN. Any insight, wisdom, or a point in the right direction would be greatly appreciated.
Thanks in advance for your help.

Replies are listed 'Best First'.
Re: Time, Time Zone Conversion
by Fletch (Bishop) on Jan 25, 2006 at 13:20 UTC

    DateTime may be what you're looking for.

    use DateTime (); my $tz = DateTime::TimeZone->new( name => "-0500" ); my $now = DateTime->now( ); print $now->time_zone->name, ": $now\n"; $now->set_time_zone( $tz ); print $now->time_zone->name, ": $now\n";