PHP时间比较

判断系统时间是否在某个时间段内

$timesolt = explode('|', $obj['timeslot']);
        $start_time = strtotime($timesolt[0]);
        $end_time = strtotime($timesolt[1]);
        //获取系统时间的时分秒时间戳
        $x = strtotime(date('H:i:s'));
        //对比时间戳查询当前时间是否在允许时间段内
        if(!($x < $end_time && $x > $start_time)){
            return resultArray(['error'=>'暂未开放']);
        }
            
strtotime:将某个指定时间段转换为时间戳:不填年月日会默认为当日
如:strtotime('14:00:00')会显示为当日下午两点的时间戳
date:获取指定格式的时间Y:m:d H:i:s
 


posted @ 2021-12-04 09:55  酒过三巡  阅读(250)  评论(0)    收藏  举报