首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找出两次不工作PHP之间的区别

找出两次不工作PHP之间的区别
EN

Stack Overflow用户
提问于 2020-10-30 13:57:19
回答 1查看 48关注 0票数 1

我想看看“最后一次看到”的时间是否在当前时间的5分钟之内。如果是时间,则将其添加到列表中。我在这里做错什么了?

进入其中的变量的值:

$cell = '2020-10-30 10:39:47‘

$current = '2020-10-30 10:41:39‘

代码语言:javascript
复制
<?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);
}
...
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-30 14:23:50

你有太多不必要的转换正在进行。我认为time()是你所需要的。

使用$cell值日期格式:

代码语言:javascript
复制
<?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);
}

?> 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64609773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档