简体   繁体   English

什么会导致php的strtotime不适用于2099年的约会?

[英]What would cause php's strtotime to not work for a date in 2099?

I have three servers, doing the following on all three servers: 我有三台服务器,在所有三台服务器上执行以下操作:

echo strtotime('2099-12-31');
echo strtotime(date('Y-m-d'));

gets me: 得到我:

Server #1: (php 5.3.8, 64bit) 服务器#1:(php 5.3.8,64bit)

4102376400
1328418000

Server 2: (php 5.3.2, 32bit) 服务器2:(php 5.3.2,32bit)

**[nothing]**
1328418000

Server #3: (php 5.3.2 - 64bit I thought it might be a php version issue) 服务器#3 :( php 5.3.2 - 64bit我认为它可能是一个php版本问题)

4102376400
1328418000

What would cause strtotime to fail on one of the servers but not the others? 什么会导致strtotime在其中一台服务器上失败而在其他服务器上失败? All three have the same Default timezone and date.timezone settings in php.ini (not sure if that would have an effect or not). 这三个在php.ini中都有相同的默认时区和date.timezone设置(不确定它是否会产生影响)。 I also turned on errors and I'm not seeing anything. 我也打开了错误,我没有看到任何东西。

Probably it is a 32-bit issue. 可能是一个32位的问题。 It works just fine on my 64-Bit Server, but my 32-bit Ubuntu returns false on strtotime('2099-12-31') 它在我的64位服务器上工作正常,但我的32位Ubuntu在strtotime('2099-12-31')返回false

For further information see this note in the manual (highlighting by me): 有关详细信息,请参阅手册中的此注释(由我突出显示):

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. 时间戳的有效范围通常是从星期五,1901年12月13日20:45:54 UTC到星期二,2038年1月19日03:14:07 UTC。 (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. (这些是与32位有符号整数的最小值和最大值相对应的日期。)此外,并非所有平台都支持负时间戳,因此您的日期范围可能不会早于Unix时期。 This means that eg dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. 这意味着例如1970年1月1日之前的日期将无法在Windows,某些Linux发行版和一些其他操作系统上运行。 PHP 5.1.0 and newer versions overcome this limitation though. PHP 5.1.0和更新的版本克服了这个限制。

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction. 对于64位版本的PHP,时间戳的有效范围实际上是无限的,因为64位可以代表任何方向上大约2930亿年。

As per the docs : 根据文档

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. 时间戳的有效范围通常是从星期五,1901年12月13日20:45:54 UTC到星期二,2038年1月19日03:14:07 UTC。 (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. (这些是与32位有符号整数的最小值和最大值相对应的日期。)此外,并非所有平台都支持负时间戳,因此您的日期范围可能不会早于Unix时期。 This means that eg dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. 这意味着例如1970年1月1日之前的日期将无法在Windows,某些Linux发行版和一些其他操作系统上运行。 PHP 5.1.0 and newer versions overcome this limitation though. PHP 5.1.0和更新的版本克服了这个限制。

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction. 对于64位版本的PHP,时间戳的有效范围实际上是无限的,因为64位可以代表任何方向上大约2930亿年。

Try eg 2019-12-31 , should work as expected. 尝试例如2019-12-31 ,应该按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM