Difference between specific time and current time [duplicate]

廉价感情. 提交于 2021-01-07 02:31:54

问题


Well i have a time in UNIX format. i need to find the difference between a specific time and current time. if difference is 5 minutes. do something.

$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
}

EDIT : How to find the difference in minutes and how to get currenttime?


回答1:


Try to get minute first using date() then compare like

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



回答2:


Not sure if this is what you are looking for...

$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";
}


来源:https://stackoverflow.com/questions/28424815/difference-between-specific-time-and-current-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!