问题
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