in reply to The function localtime(time) returns wrong month . How to overcome this problem ??

The reason why month indexes were originally made to start at 0, not 1, is because it's primarily intended to be used as an array index. So you can do this:
@month = qw(january february march april may june july august septembe +r october november december); $m = 1; print $month[$m]; # prints "february"

(No, I lied, actually the primary reason is backward compatibility with C. But I digress.)

So perhaps you can do this?

$m = 1; print +(1 .. 12)[$m]; # prints "2"

Now, it might be easier still, to just increment the month number.

$m++;
  • Comment on Re: The function localtime(time) returns wrong month . How to overcome this problem ??
  • Select or Download Code