方式一、判断小时和分钟
<?php
date_default_timezone_set("Asia/Shanghai");//设置时区,亚洲/上海时区
$time = intval (date("Hi"));
if ($time > "800" && $time < "1130") {echo "在指定的时间段内";
}
?>
方式二、只判断小时
<?php
date_default_timezone_set("Asia/Shanghai");//设置时区,亚洲/上海时区
$h = intval(date("H"));
if ($h > 24 || $h < 6) {echo '在凌晨时间段内';
}
?>
方式三、指定的时间段内
<?php
date_default_timezone_set('PRC');//设置时区,其中PRC为“中华人民共和国”
$currentTime=strtotime(date("H:i"));//获得当前小时和分钟的时间时间戳
$startTime=strtotime('10:50');//获得开始时间的时间戳
$endTime=strtotime('10:59');//获得结束时间的时间戳
if($currentTime>$startTime && $currentTime<$endTime){echo '在指定时间段内';
}else{echo '不在指定时间段内';
}
?>