Php abs+STROTIME对于不同的日期减法给出相同的结果
我有这个密码:Php abs+STROTIME对于不同的日期减法给出相同的结果,php,strtotime,Php,Strtotime,我有这个密码: <?php $data = array(array("1","name1","2050-10-10"),array("2","name1","2051-10-10")); $date = date("Y-m-d"); $x = 2; foreach($data as $day) { $interval[] = abs(strtotime($date) - strtotime($day[$x])); $interval[] = $day[$x]; } var_dump(
<?php
$data = array(array("1","name1","2050-10-10"),array("2","name1","2051-10-10"));
$date = date("Y-m-d");
$x = 2;
foreach($data as $day)
{
$interval[] = abs(strtotime($date) - strtotime($day[$x]));
$interval[] = $day[$x];
}
var_dump($interval);
?>
但返回:
array(1) {
[0]=> array(4) {
[0]=> int(1418338800)
[1]=> string(10) "2050-10-10"
[2]=> int(1418338800)
[3]=> string(10) "2051-10-10"
}
}
array(4) {
[0]=>
int(1130716800)
[1]=>
string(10) "2050-10-10"
[2]=>
int(1162252800)
[3]=>
string(10) "2051-10-10"
}
我不明白为什么1418338800的值保持不变,我想知道如何解决这个问题
提前非常感谢
遵循@Jonathan Kuhn的建议:
<?php
echo strtotime("2051-10-10");
echo strtotime("2050-10-10");
echo strtotime("2040-10-10");
echo strtotime("2039-10-10");
echo strtotime("2038-10-10");
echo strtotime("2037-10-10");
echo strtotime("2036-10-10");
?>
问题来自32位系统。您的问题表明使用了两个不同的日期,但在您的代码中都是2050-10-10。你确定粘贴的代码正确吗?可能是整数溢出?2038年1月19日UTC 03:14:07时32位系统的时间戳用完了。请检查两个日期的时间戳是否不相同,以及每个日期的时间戳是多少?@Jonathan Kuhn我不知道32位系统的时间戳限制。。。我能找到解决办法吗?在32位系统上,不要对2038年以后的日期使用时间戳。您可以使用datetime类。见:
empty line
empty line
empty line
empty line
empty line
2138738400
2107202400