Time::localtime problems

Discussion in 'Perl' started by Gerry George, May 26, 2004.

  1. Gerry George

    Gerry George Guest

    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.
    Gerry George, May 26, 2004
    #1
    1. Advertising

  2. Gerry George

    Purl Gurl Guest

    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
    Purl Gurl, May 26, 2004
    #2
    1. Advertising

  3. Gerry George

    Joe Smith Guest

    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
    Joe Smith, May 26, 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. Stephen
    Replies:
    1
    Views:
    1,190
    Purl Gurl
    May 19, 2004
  2. OleMacGeezer

    time.localtime() Format Question

    OleMacGeezer, Aug 20, 2006, in forum: Python
    Replies:
    1
    Views:
    458
    Greg Krohn
    Aug 20, 2006
  3. KW
    Replies:
    1
    Views:
    1,795
    Eric Sosman
    Dec 8, 2004
  4. Rich Bogle

    time configuration for localtime

    Rich Bogle, Apr 23, 2004, in forum: Perl Misc
    Replies:
    8
    Views:
    192
    Glenn Jackman
    Apr 23, 2004
  5. Leendert Bottelberghs

    time zone offset calc with localtime and gmtime

    Leendert Bottelberghs, Apr 4, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    757
    Mothra
    Apr 5, 2005
Loading...

Share This Page