Returned wrong Year

S

sam

Hi,

I used the following perl code display date , month and year, but the
year is shown as 104 instead of 2004:

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
print "Month: ".$mon."\n";
print "Year: ".$year."\n";

Result:
It is now Sat Dec 25 11:11:01 2004
Month: 11
Year: 104

What is the correct way to retrieve the value of the year?

Thanks
Sam
 
M

Matt Garrish

sam said:
Hi,

I used the following perl code display date , month and year, but the year
is shown as 104 instead of 2004:

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
print "Month: ".$mon."\n";
print "Year: ".$year."\n";

[snip expected results]
What is the correct way to retrieve the value of the year?

Please read the documentation for the function you're using. It explains the
behaviour you're witnessing.

http://www.perldoc.com/perl5.8.4/pod/func/localtime.html

Matt
 
J

Jürgen Exner

sam said:
I used the following perl code display date , month and year, but the
year is shown as 104 instead of 2004:

Your code has a well-known y2k problem. You may want to read the
documentation for the functions you are using.
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
time; print "Month: ".$mon."\n";
print "Year: ".$year."\n";

Result:
It is now Sat Dec 25 11:11:01 2004
Month: 11
Year: 104

What is the correct way to retrieve the value of the year?

This is described _AT_LENGTH_WITH_SAMPLE_CODE_ in the documentation of the
localtime() function.

jue
 

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

Similar Threads

localtime(time()) 16
time format +1 hour 15
Taskcproblem calendar 4
improve subroutine.. seems klunky 14
Date Problem 6
TimeDate conversion to string. 8
localtime and mktime 2
time configuration for localtime 8

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top