ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
Re: Is this a bug in localtime
by Abigail other posts by this author
Aug 29 2008 3:56AM messages near this date
Is this a bug in localtime | Smoke [5.11.0] 34234 FAIL(F) MSWin32 WinXP/.Net SP3 (x86/2 cpu)
On Fri, Aug 29, 2008 at 04:02:33PM +0530, Pankaj Singh wrote:
>  Hi All,
>  
>  I was trying to form timeStamp from localtime function in perl.
>  
>  Perl version  : v5.8.8 built for i386-linux-thread-multi
>  
>  Output of date command
>  --------------------------------------
>  
>  Fri Aug 29 15:56:14 IST 2008
>  
>  The code I wrote in perl
>  ------------------------------------
>  
>  my ($sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2,
>  3, 4, 5 ];
>  
>  print "$year  $month  $day $hour $min \n";
>  
>  printf("%04d-%02d-%02d %02d:%02d\n",$year+1900,$month,$day,$hour, $min);
>  
>  print "\n";
>  @timeData = localtime(time);
>  print join(' ', @timeData);
>  
>  
>  The output was
>  ----------------------
>  108  7  29 15 53
>  2008-07-29 15:53
>  10 53 15 29 7 108 5 241 0
>  
>  But i was expecting
>  Something like
>  2008-08-29 15:53

This is not a bug, and it's documented behaviour.

Just as localtime() returns 1900 based years, it returns months 0 based.
So, January is month 0, February is month 1, etc. Thus, where you add
1900 to the year, you should add 1 to the month.



Abigail
Thread:
Pankaj Singh
Abigail

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved