Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:2038年1月19日以后的时间和日期_Php_Strtotime - Fatal编程技术网

PHP:2038年1月19日以后的时间和日期

PHP:2038年1月19日以后的时间和日期,php,strtotime,Php,Strtotime,我使用strotime函数查找两个给定日期之间的差异,如下所示: $diff_in_mill_seconds = strtotime($ToDate) - strtotime($FromDate); $difference_in_years = round($diff_in_mill_seconds / (365*60*60*24),1); 当$ToDate超过2038-01-19时,此脚本失败 PHP官方文档说: 时间戳的有效范围通常是从1901年12月13日星期五20:45:54 UTC到

我使用strotime函数查找两个给定日期之间的差异,如下所示:

$diff_in_mill_seconds = strtotime($ToDate) - strtotime($FromDate);
$difference_in_years = round($diff_in_mill_seconds / (365*60*60*24),1);
当$ToDate超过2038-01-19时,此脚本失败

PHP官方文档说:

时间戳的有效范围通常是从1901年12月13日星期五20:45:54 UTC到2038年1月19日星期二03:14:07 UTC

PHP文档还说:

不建议将此函数用于数学运算。最好在PHP5.3及更高版本中使用DateTime::add()和DateTime::sub(),或者在PHP5.2中使用DateTime::modify()

我不能使用DateTime::add()和DateTime::sub(),因为服务器上的PHP版本是5.2

那么,如何使用PHP5.2计算两个日期(2038-01-19之后)之间的年差呢?

这是UNIX。它已在64位PHP实现中或通过使用
DateTime::diff
修复,后者在内部不使用整数,因此不会出现问题


你两者都需要。没有交换平台就没有真正的修复方法。

证实了我的直觉——UNIX时间戳正在滚动,因为您在32位机器上。切换到64位机器,您将能够将大于2038的日期表示为UNIX timestamp.PHP 5.2,而不是64位机器?对不起,什么都帮不了你。您只需要更新版本。@Sabari
DateTime::add
是在5.3中特别引入的。@deceze哦,好的。谢谢你让我知道。我在这里回答了: