in reply to Re^2: Date conversion in perl?
in thread Date conversion in perl?

No. That's not the what localtime takes for input. And even if it did, localtime does not produce the requested output.

In fact, that number is so large that it doesn't fit in a 32-bit int, and thus my localtime can't handle it:

>perl -wle"print scalar(localtime(20100302165019));" Use of uninitialized value in print at -e line 1.

Replies are listed 'Best First'.
Re^4: Date conversion in perl?
by ww (Archbishop) on Mar 03, 2010 at 13:49 UTC
    ww@GIG:~$ perl -wle 'print scalar(localtime(20100302165019));' Wed Dec 31 18:59:59 1969 ww@GIG:~$ perl -wle 'print scalar(localtime(20100302165219));' Wed Dec 31 18:59:59 1969 ^ ww@GIG:~$ perl -wle 'print scalar(localtime(20100305165219));' Wed Dec 31 18:59:59 1969 ^ ww@GIG:~$ perl -wle 'print scalar(localtime(23100305165219));' Wed Dec 31 18:59:59 1969 ^

    32bit 5.10 Linux

      FYI that date, 1 second before epoch, corresponds with a time value -1 (hex FFFFFFFF) which is commonly used as an overflow value for integer arithmetic.

      It's a different failure mode, but it's still failing by returning the date for -1 instead of returning undef.

      I imagine that some of the work in this area is done by the underlying C library, so you can expect differences between systems.

      I believe that might also be changed in 5.12 to avoid the year 2038 overflow.

      Update: Confirmed:

      $ /usr/bin/perl -le'print scalar localtime "201003031234"' Wed Dec 31 18:59:59 1969 $ ./perl -le'print scalar localtime "201003031234"' Fri Jul 14 19:20:34 8339