First off, I'd like to say that I'm relatively new to the world of Perl (~4 months) and find the open and sharing atmosphere of perlmonks.org extremely conducive to learning. Thanks to everyone who contributes to this wonderful site.

Now for the business at hand:

I'm trying to parse a date of the form:
Mon Apr 18 15:17:29 2005
and converting it to unix time (epoch seconds) using Time::Local. Here is the code I'm using:

#!/usr/bin/perl -w use strict; use Time::Local; my %months = ( 'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11, ); my ($wday, $mon, $mday, $hr, $min, $sec, $year); my $date = 'Mon Apr 18 15:17:29 2005'; if (($wday, $mon, $mday, $hr, $min, $sec, $year) = $date =~ /(\w+)\s+( +\w+)\s+(\d+)\s(\d+):(\d+):(\d+)\s+(\d+)/) { foreach my $key (keys %months) { $mon =~ s/$key/$months{$key}/i; } my $local_epoch = timelocal($sec, $min, $hr, $mday, $mon, $year); my $gmt_epoch = timegm($sec, $min, $hr, $mday, $mon, $year); }

Here's what is returned:

$local_epoch = 1113851849
$gmt_epoch = 1113837449
Seeing as how my $ENV{TZ} = US/Eastern
I'm wondering why the number of seconds returned for $local_epoch is larger than that returned for $gmt_epoch? During daylight saving time (EDT), the difference between GMT and local time is -4 hours (ie: we're 4 hours behind GMT time) on the East Coast.

Shouldn't the value $gmt_epoch be larger than that of $local_epoch?

Thanks in advance,
John


In reply to Parsing Dates by njcodewarrior

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.