On Mon, 26 Apr 2004 06:07:03 -0700 (PDT)
  Alok Bhatt hammered out:

> I am facing this strange problem related to dates.
> When I print the date using the system's date command,
> it prints correctly. But when I do the same using
> localtime, it shows the month as wrong (1 month
> previous.
>
> bash-2.03$ perl -e '@a=localtime; print "@a\n"'
> 18 4 8 26 3 104 1 116 0
>         ^^^
[Snip]
> bash-2.03$ date
> Mon Apr 26 08:04:23 GMT 2004
> bash-2.03$ 
>
> It shows the month as March (3) instead of April. What
> could I be doing wrong?

I'm only a raw beginner in Perl, so hopefully I'm giving you the right
information. I'm sure others in the list will point out my mistakes :)

localtime returns the following:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)

with $mon, the month, being in the range (0 .. 11). So January is 0 to
December being 11. You aren't doing anything wrong, just misinterpreting
the information.

HTH

-- 
     Patrick Heffernan     * Over the years, I've developed my sense of 
 Maryvale Computer Service * deja vu so acutely that now I can remember 
       Warwick - QLD       * things that *have* happened before ... 
       07  4667 3807       *  


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to