First, welcome at the Monastery.  There are a couple of issues with your code, but as it's time to go to bed in my local TZ, I hope some other kind monks will point them out :)

Anyhow, if the idea is to convert those dates (with any TZ) into EST, the whole thing can be simplified considerably, because Date::Manip already does most of the magic while parsing the input string...

#!/usr/bin/perl -w use strict; use Date::Manip; Date_Init("TZ=EST"); # target TZ # use your filehandle here instead of DATA while (my $date_anyTZ = <DATA>) { chomp $date_anyTZ; # get rid of '~' to make date parseable by Date::Manip $date_anyTZ =~ tr/~/ /; my $date_EST = UnixDate(ParseDate($date_anyTZ), "%Y-%m-%d %H:%M:%S + %Z"); printf "%-24s --> %s\n", $date_anyTZ, $date_EST; } __DATA__ 20050526~18:15:06 GMT 20040401~01:12:02 GMT 20060201~00:59:01 GMT 20060401~01:01:01 EST 20040201~10:10:01 -0600 20010901~04:23:05 -0400 20050526~18:15:06 GMT 20040401~01:12:02 GMT 20000101~00:59:01 -0200 19841223~04:22:06 MST

Prints

20050526 18:15:06 GMT --> 2005-05-26 13:15:06 EST 20040401 01:12:02 GMT --> 2004-03-31 20:12:02 EST 20060201 00:59:01 GMT --> 2006-01-31 19:59:01 EST 20060401 01:01:01 EST --> 2006-04-01 01:01:01 EST 20040201 10:10:01 -0600 --> 2004-02-01 11:10:01 EST 20010901 04:23:05 -0400 --> 2001-09-01 03:23:05 EST 20050526 18:15:06 GMT --> 2005-05-26 13:15:06 EST 20040401 01:12:02 GMT --> 2004-03-31 20:12:02 EST 20000101 00:59:01 -0200 --> 1999-12-31 21:59:01 EST 19841223 04:22:06 MST --> 1984-12-23 06:22:06 EST

which looks OK to me.


In reply to Re: TimeZone Assistance Requested by almut
in thread TimeZone Assistance Requested by Knoperl

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.