如何在PHP中比较时间?
我想这样说:
$ThatTime ="14:08:10"; $todaydate = date('Y-m-d'); $time_now=mktime(date('G'),date('i'),date('s')); $NowisTime=date('G:i:s',$time_now); if($NowisTime >= $ThatTime) { echo "ok"; }
上面的代码无法正常打印。我期望如此。
$ThatTime =”14:08:10”; if (time() >= strtotime($ThatTime)) { echo “ok”; }
使用DateTime(也考虑时区)的解决方案。
DateTime
$dateTime = new DateTime($ThatTime); if ($dateTime->diff(new DateTime)->format('%R') == '+') { echo "OK"; }