in reply to Convert dates with Time::Local

use timegm instead of timelocal.

perldoc Time::Local

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Convert dates with Time::Local
by jeanluca (Deacon) on Feb 13, 2006 at 15:34 UTC
    Thnx, Do you know how to use timegm when you have a julian day and not a month and day ?

    Luca

      Like so:

      use Time::Local qw/timegm_nocheck/; my $date_string = "2005301"; # The 301st day of 2005 my ($year,$julian_day) = $date_string =~ /^(\d\d\d\d)(\d\d\d)$/; my $gmt = timegm_nocheck 0,0,0,$julian_day,0,$year; # ... do something with the gmt value

      Way back in the days of perl4, timelocal.pl (from whence Time::Local is derived) did no validation of the numbers since it is a straight numeric calculation that does not depend on how many days there are in a given month or how many hours in a day, etc. timegm_nocheck and timelocal_nocheck implement the modern-day equivalents of this idea.

      But, you'd know this if you'd read the documentation

      I don't think I'd use timegm with a Julian date.

      Jan 1st 1970 has a Julian date of 2440587. Surely you can just subtract that from the Julian date you have and then multiply by the number of seconds in a day to get the number of seconds since the epoch. This, of course, assumes that your computer uses 1970-01-01 00:00:00 as its epoch.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Julian dates and julian days are different things. The latter is just the number of days since the start of the year. Jan 1 is julian day 1, Feb 1 is julian day 32, Feb 2, day 33, and so on.