Returned wrong Year

Discussion in 'Perl Misc' started by sam, Dec 25, 2004.

  1. sam

    sam Guest

    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
    sam, Dec 25, 2004
    #1
    1. Advertising

  2. sam

    Matt Garrish Guest

    "sam" <> wrote in message
    news:cqinh9$2ied$...
    > 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
    Matt Garrish, Dec 25, 2004
    #2
    1. Advertising

  3. sam wrote:
    > 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
    Jürgen Exner, Dec 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    1
    Views:
    407
    Thomas Weidenfeller
    Apr 1, 2004
  2. Otuatail

    Week of year to full Year

    Otuatail, Dec 8, 2003, in forum: HTML
    Replies:
    4
    Views:
    963
    Toby A Inkster
    Dec 8, 2003
  3. Wen
    Replies:
    4
    Views:
    466
    Simon Saunders
    Dec 12, 2003
  4. Veerle
    Replies:
    2
    Views:
    411
    niceguy
    Aug 20, 2003
  5. David Woodward
    Replies:
    5
    Views:
    377
    Dr John Stockton
    Feb 2, 2004
Loading...

Share This Page