Today I got this problem when executing the gmdate in PHP.
echo gmdate('Y-m-d\T00:00:00Z', strtotime("9999-12-31T00:00:00Z"));
While normally it should return “9999-12-31T00:00:00Z”, but which made me surprised is that finally I got a “1970-01-01T00:00:00Z”.
And I tried this command in another PC, which returned me the good answer.
Where did the 1970 came from? I guessed this might be something like the start of the world or the creation of PHP or etc.
Bon, ok ! Let’s check out the difference between the version of the system and the version of PHP.
The first PC (Ubuntu)which returned me a “1970” got this :
# uname -a
Linux 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux
The second PC which returned me the “9999” got this :
Linux 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
I think I got the answer, if it is a 32-bit unix-like system, the time stamp is based in seconds, and the biggest by calculating 2^32 something like that will be a number 2147483647, so nearly 68 years, and the begin year for unix time (defined by IEEE ?) is 1970, so the max is 1970 + 68 = 2038. So here if the year is bigger than 2038, there will be an integer overflow, an error of course, all… will return back to the beginning 🙂
Find more explanation in wiki :
Find an answer in stack overflow :