Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

It's been a while since i've had to use timelocal and can not seem to remember if the $mday is always double digit? For example, I can grab the day of the month using...
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +);
but is the second day of the month 2 or 02?

Replies are listed 'Best First'.
Re: timelocal brain freeze
by Zaxo (Archbishop) on Nov 11, 2002 at 06:50 UTC

    It sounds as if you need some particular output format for dates and times. See &POSIX::strftime for perl usage and 'man 3 strftime' for details of the formats available to this very handy time & date formatting function.

    The best part is that you never need to parse the output of localtime. &POSIX::strftime takes the same time structure that localtime produces, so localtime can be used as a singlethe second argument for strftime.

    After Compline,
    Zaxo

Re: timelocal brain freeze
by Enlil (Parson) on Nov 11, 2002 at 06:04 UTC
    The second day of the month is 2. If you it matters that the one zero is there before the two, one could always use
    $mday = sprintf("%02d",$mday);

    -enlil

Re: timelocal brain freeze
by roik (Scribe) on Nov 11, 2002 at 15:12 UTC
    perldoc has this to say :
    $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December