in reply to Re^2: Extract value between quotes
in thread Extract value between quotes
The date/time returned by localtime should already be in your system’s timezine. However, for general conversions between timezones I like the OO-interface to the Date::Manip family of modules. Daylight saving time is handled correctly. Here is some example code:
#! perl use strict; use warnings; use feature 'state'; use Date::Manip; my $est = localtime; my $tz = new Date::Manip::TZ; my ($error, $date) = $tz->convert(ParseDate($est), 'Australia/Brisbane', 'CET'); if ($error) { warn "Error $error. Failed to convert date and time$!"; } else { my $cet = sprintf("%s %s %d %02d:%02d:%02d %d", get_day_of_week($date), get_month($date->[1]), @$date[2 .. 5, 0]); print "My time (EST) is $est\n"; print "Your time (CET) is $cet\n"; } sub get_day_of_week { state $days = [ qw(Mon Tue Wed Thu Fri Sat Sun) ]; my ($date) = @_; my $base = new Date::Manip::Base; my $index = $base->day_of_week($date); return $days->[ $index - 1 ]; } sub get_month { state $months = [ qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov +Dec) ]; my ($month) = @_; return $months->[ $month - 1 ]; }
Update: Shortened the call to sprintf.
Output:
16:42 >perl 753_SoPW.pl My time (EST) is Tue Oct 22 16:42:35 2013 Your time (CET) is Tue Oct 22 08:42:35 2013 16:42 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|