【问题标题】:Difference between specific time and current time [duplicate]特定时间与当前时间之间的差异[重复]
【发布时间】:2015-04-10 01:56:04
【问题描述】:

嗯,我有一个 UNIX 格式的时间。我需要找到特定时间和当前时间之间的差异。如果相差 5 分钟。做点什么。

$sp_time = 1400325952;//Specific time
$currentTime = //current time in UNIX format

$difference = $currentTime - $sp_time;
if($difference >= 5)//if difference is less than or equal to 5minutes
{
    //DO SOME STUFF
}

编辑:如何找到分钟的差异以及如何获取当前时间?

【问题讨论】:

  • 您的问题是什么?描述您的问题/错误。

标签: php mysql date datetime time


【解决方案1】:

尝试先使用date() 获取分钟数,然后进行比较

$sp_time = 1400325952;//Specific time
$currentTime = time(); // current time 
$difference = $currentTime - $sp_time;
if(date('i',$difference) >= '5') {
    //DO SOME STUFF
}

【讨论】:

    【解决方案2】:

    不确定这是否是您要找的...

    $sp_time = 1400325952;//Specific time
    $currentTime = time(); // current time 
    $diff = abs($currentTime - $sp_time);
    
    $mins = round($diff / 60);
    
    if ($mins <= 5) {
    echo "difference is less than or equal to 5minutes: $mins";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多