I'm a nubie Perl programmer. I'm working on a Perl cgi gui. Part of the data it will display are datetimes that are stored in a database in GMT. I want to give the user the option of specifying which time zone the dates are displayed in. I have put the following code together to convert the GMT time to the corresponding timezone.
my $datetime = "2005-06-22 20:04:47"; #to be passed in
my $timezone = "EST"; #to be passed in
my ( $year_month_days, $hours_mins_secs ) = split ' ', $datetime;
my ( $year, $month, $day ) = split '-', $year_month_days;
my ( $hours, $minutes, $seconds ) = split ':', $hours_mins_secs;
$month -= 1;
my $time = timegm($seconds, $minutes, $hours, $day, $month, $year);
my $template = "%Y-%m-%d %H:%M:%S";
print = time2str($template, $time, $timezone);
This doesn't take into account that the GMT date given falls within the daylight savings period for the eastern timezone so it returns a datetime that is an hour off. Is there a method that I can call that determines whether a daylight savings shift should take place based on a GMT time and a given timezone? Is anyone aware of any modules or code that may already be out there that will do what I'm looking for? I've been looking through stuff on the net, but I've not found anything that goes beyond the daylight savings flag that is returned by the localtime method. Thanks for taking the time to look at this.
my $datetime = "2005-06-22 20:04:47"; #to be passed in
my $timezone = "EST"; #to be passed in
my ( $year_month_days, $hours_mins_secs ) = split ' ', $datetime;
my ( $year, $month, $day ) = split '-', $year_month_days;
my ( $hours, $minutes, $seconds ) = split ':', $hours_mins_secs;
$month -= 1;
my $time = timegm($seconds, $minutes, $hours, $day, $month, $year);
my $template = "%Y-%m-%d %H:%M:%S";
print = time2str($template, $time, $timezone);
This doesn't take into account that the GMT date given falls within the daylight savings period for the eastern timezone so it returns a datetime that is an hour off. Is there a method that I can call that determines whether a daylight savings shift should take place based on a GMT time and a given timezone? Is anyone aware of any modules or code that may already be out there that will do what I'm looking for? I've been looking through stuff on the net, but I've not found anything that goes beyond the daylight savings flag that is returned by the localtime method. Thanks for taking the time to look at this.