我正试图比较时间,看看它是否小于设定的时间,如果是,做点什么…如何才能做到这一点?
例如,我到目前为止有这个。
$now = strtotime(date('g:i a'));
$event_time = strtotime("10:00 am");
有了这两个变量,我如何检查event_time是否比当前"现在"时间早5分钟?
谢谢…
当前不需要strtotime
。时间戳是以秒为单位的值,只需做一些计算:
$now = time();
$event_time = strtotime("10:00 am");
if( ($now - $event_time) == (5 * 60)) // 5 minutes * 60 seconds, replace with 300 if you'd like
{
// 5 minutes before
}
Demo -但是您应该使用上面的$now
变量代码