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,


In reply to Re^3: Extract value between quotes by Athanasius
in thread Extract value between quotes by kaka_2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.