我正在使用 strtotime 函数来查找两个给定日期之间的差异,如下所示:
$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 文档还说:
不建议将此函数用于数学运算。最好在 PHP 5.3 及更高版本中使用 DateTime::add() 和 DateTime::sub(),或者在 PHP 5.2 中使用 DateTime::modify()。
我不能使用 DateTime::add() 和 DateTime::sub() 因为服务器上的 PHP 版本是 5.2。
那么,如何使用 php 5.2 计算两个日期(超过 2038-01-19 年)之间的差异?