php按时分时间段判断语句

2025-04-24 12:54:08
推荐回答(4个)
回答1:

临时写了一段,你看看,


date_default_timezone_set('PRC');//设置时区,其中PRC为“中华人民共和国”

$j=date("H:i");获得当前小时和分钟的时间
$h=strtotime($j);//获得当前小时和分钟的时间时间戳
$z=strtotime('00:00');//获得指定分钟时间戳,00:00
$x=strtotime('00:29');//获得指定分钟时间戳,00:29
if($h>$z && $z<$x){
    echo '显示时间是00:00到00:29分之间';
}
?>

回答2:

$date=date("H:i:s");
if($date> '00:00:00' && $date < '00:29:59'){
echo '111111111111111';
}elseif($date> '00:30:00' && $date < '00:30:59'){
echo '2222222222222';
}elseif($date> '00:31:00' && $date < '00:59:59'){
echo '2222222222222';
}else{

}

你说的时间段有点不明确,大概就是上面那样,按需要来改就行啦,加秒数可以很好判断如:0-29分包不包括第29分钟。
用<=之类的符号也行。
?>

回答3:

$now=date('His',time());
$intNow=intval($now);//将当前时间转换成整形
//echo $intNow;//输出转换好的整形测试
if($intNow>0&&$intNow<2900){
echo '111';
}elseif($intNow>2900&&$intNow<3000){
echo '222';
}elseif(){
//code
}

回答4:

习惯了封装,已实验,完全通过,望采纳
function in_quarters($time,$from,$to){
$time=intval(date("i",$time));
$from=intval(date("i",strtotime($from)));
$to=intval(date("i",strtotime($to)));
if($time>=$from && $time<$to){
return true;
}else{
return false;
}
}

if(in_quarters(time(),"09:00","09:29")){
echo "1111";
}
if(in_quarters(time(),"09:29","09:30")){
echo "2222";
}
if(in_quarters(time(),"09:30","09:59")){
echo "3333";
}