Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why perl cannot convert unix timestamp over year 2038?

Tags:

perl

year2038

I am trying to use below perl command to convert epoch times to readable localtime:

       bash-3.2$ perl -le print\ scalar\ localtime\ 32503651200
       Thu Mar  9 19:13:52 1911

Below year 2038 is possible to be converted correctly, but for year numbers is greater than 2038 I couldn't get expected result.

Please advise how to fix. Thanks.

like image 639
Fehan Avatar asked Dec 06 '25 13:12

Fehan


1 Answers

The year 2038 bug on 32 bit systems was worked around in Perl 5.12.0 (64 bit systems are unaffected by the 2038 bug). I know because I did it (with help). :) Simply upgrade your Perl and the problem (and a lot of others) is solved.

Alternatively, use a date library such as DateTime. It does not rely on system time functions (the root of the 2038 bug), is unaffected by the y2038 bug, and is generally much, much easier to use.

If you can't upgrade Perl and must use localtime and gmtime, you can use Time::y2038 to get versions of those functions unaffected by the 2038 bug.

like image 73
Schwern Avatar answered Dec 09 '25 16:12

Schwern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!