[英]Finding the difference between two times not working PHP
我正在尝试查看“上次看到”时间是否在当前时间的 5 分钟内。 如果时间是,它将被添加到列表中。 我在这里做错了什么?
变量的值进入这个:
$cell = '2020-10-30 10:39:47'
$current = '2020-10-30 10:41:39'
<?php
...
$current = date('Y-m-d H:i:s');
$datetime_from_last_seen = date("Y-m-d H:i", strtotime("-5 minutes", strtotime($cell)));
$datetime_from_current = date("Y-m-d H:i", strtotime("-5 minutes", strtotime($current)));
$dtflsString = strtotime($datetime_from_last_seen);
$dtfcString = strtotime($datetime_from_current);
if ($dtflsString < $dtfcString)
{
echo "<br>" . "Last Seen: " . $cell . " is within 5 minutes of: " . $current . "<br>";
array_push($my_array_of_times_seen, $cell);
}
...
?>
您正在进行太多不必要的转换。 我认为time()
就是你所需要的。
使用您的$cell
起息日期格式:
<?php
$current = time();
$last_seen = strtotime($cell);
$difference = $current - $last_seen;
if ($difference >= 0 && $difference <= (60*5)){ //within and including exactly 5 minutes
array_push($my_array_of_times_seen, $cell);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.