bug in localtime()? 
Author Message
 bug in localtime()?

I am having a problem with localtime in that it seemingly returns the
wrong month.  For example, it says that today is May 22 when it's actually
June 22.  

The script I wrote to test this is below:

#! /usr/bin/perl
($sec, $min, $hour, $monthday, $month, $year, $wday, $yday, $isdst) =
localtime(time);
print "$hour:$min:$sec $month-$monthday-$year $wday $yday $isdst \n";

and the output is:
8:53:31 5-22-95 4 172 0
while the Unix date command yields:
Thu Jun 22 08:53:33 GMT-0700 1995

This particular version of perl is 4.0.1.8 rev 36.

Any ideas?  Should I just autoincrement the month before I use the value?

--
Chad Jones      Network Manager |     Needs no refrigeration; however
UCLA Graduate School of         |     many people prefer the chilled,
Education & Information Studies | refrigerated taste of Pepto-Bismol.



Mon, 08 Dec 1997 03:00:00 GMT  
 bug in localtime()?

Quote:

> I am having a problem with localtime in that it seemingly returns the
> wrong month.  For example, it says that today is May 22 when it's actually
> June 22.  

Turns out that $month and $wday are zero-relative.  I guess I should have
read the camel book more closely.

Thanks for the replies.

--
Chad Jones      Network Manager |     Needs no refrigeration; however
UCLA Graduate School of         |     many people prefer the chilled,
Education & Information Studies | refrigerated taste of Pepto-Bismol.



Mon, 08 Dec 1997 03:00:00 GMT  
 bug in localtime()?

Quote:

>Any ideas?  Should I just autoincrement the month before I use the value?

Yep! this is exactly what is described on page 160 of the Camel book. A
highly recommanded buy!

$month is zero-based (range 0..11) This is also true for $wday (0..6)

O. Burdet
______________________________________________________________________
Olivier L. Burdet, IBAP, Beton Arme et Precontraint
                   Reinforced and Prestressed Concrete
Swiss Federal Institute of Technology, EPFL, Ecublens, CH-1015 Lausanne
Tel: +41-21 693 28 91,  Fax: +41-21 693 58 85

WWW   : http://ibapwww.epfl.ch/person/burdet.htm



Tue, 09 Dec 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. BUG in localtime(time)?

2. Bug with localtime() in Perl 5.004 and 5.005

3. A bug in localtime()

4. bug in localtime()???

5. localtime bug in activestate 805

6. localtime and Win32: The april fool's bug

7. localtime () - perl's bug ?

8. problem with function localtime, is it Y2K bug.

9. localtime (perldoc -f localtime didn't help)

10. localtime -> reverse -> localtime

11. localtime() and tm_zone

12. why doesn't localtime()[2] work?

 

 
Powered by phpBB® Forum Software