我想看看“最后一次看到”的时间是否在当前时间的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);
}
...
?>发布于 2020-10-30 14:23:50
你有太多不必要的转换正在进行。我认为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);
}
?> https://stackoverflow.com/questions/64609773
复制相似问题