Time::localtime problems

G

Gerry George

I have a problem in that the month I get returned from the localtime
is always the prior month rather than the current month. The following
is a little program that just prints out the localtime components. For
reference, today's date is May 26, 2004 (5/26/2004), but I always get
4/26/2004.

################################################
#!/usr/perl5/bin/perl

use Time::localtime;
$lt = localtime;

$mevsyr = $lt->year;
$mevsccyy = $lt->year;
$mevsmo = $lt->mon;
$mevsday = $lt->mday;
$mevshour = $lt->hour;
$mevsmin = $lt->min;

print "mevsyr: $mevsyr\n";
print "mevsccyy: $mevsccyy\n";
print "mevsmo: $mevsmo\n";
print "mevsday: $mevsday\n";
print "mevshour: $mevshour\n";
print "mevsmin: $mevsmin\n";
###############################################

results:

mevsyr: 104
mevsccyy: 104
mevsmo: 4 ????????????? s/b 5
mevsday: 26
mevshour: 12
mevsmin: 31


The above is true regardless of platform (Unix or Windows). I use perl
5.00503 on Unix and perl 5.8 on Windows. I am relatively new at this
so I could be doing something wrong, but I don't think so. Any help
you can give is greatly appreciated. Thanks.
 
J

Joe Smith

Gerry said:
I have a problem in that the month I get returned from the localtime
is always the prior month rather than the current month.

It's designed to be an index into an array, which starts with index 0.

$month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$lt->mon];

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top