Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Time::localtime problems

Reply
Thread Tools

Time::localtime problems

 
 
Gerry George
Guest
Posts: n/a
 
      05-26-2004
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.
 
Reply With Quote
 
 
 
 
Purl Gurl
Guest
Posts: n/a
 
      05-26-2004
Gerry George wrote:

(snipped)

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


> $mevsmo = $lt->mon;


$mevsmo = $lt->mon + 1;


Purl Gurl
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      05-26-2004
Gerry George wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving the web, charset problems and symbols problems Sak Na rede Ruby 0 01-30-2009 05:05 AM
Problems, problems for newbie Shelly ASP .Net 1 09-03-2007 02:10 AM
Problems compiling simple C++ code (also problems with std::string) Susan Baker C++ 2 06-26-2005 01:43 AM
Re: sound problems and modem problems Harold Potter Computer Support 5 12-04-2003 04:12 PM



Advertisments