Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Corion (Pope)
on Feb 09, 2006 at 09:56 UTC ( #529035=note: print w/ replies, xml ) Need Help??


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

I wonder if you'd care to suggest how we could improve the documentation for localtime to make it more obvious how to solve your problem. Currently the docs say this:

... $mday is the day of the month, and $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December.

If you're formatting dates for outputting to the user, let me recommend a proper date formatting tool, like POSIX::strftime or DateTime or Date::Calc.

If all you need is the number of the month, how about just adding 1 to the number?


Comment on Re: The function localtime(time) returns wrong month . How to overcome this problem ??
Select or Download Code
Re^2: The function localtime(time) returns wrong month . How to overcome this problem ??
by nevyn (Monk) on Feb 23, 2006 at 21:28 UTC

    Change it from...

    $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December.

    ...to...

    $mon is the month offset, in the range 0..11 with 0 indicating January and 11 indicating December.

    ...as the former implies that $mon is the number of the month which people might assume starts at 1 (and stop reading). But my guess is that anyone who has a problem hasn't read the current docs. (but, hey at least they don't just assume tm_year is the last two digits nowadays).

    --
    James Antill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://529035]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-07-02 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls