php处理业务打开和关闭时间

php处理业务打开和关闭时间,php,Php,尝试获取每个门店的打开和关闭状态,如果在操作时间内,则返回打开,如果未返回关闭 例如:周一至周五:上午11:00至凌晨2:00(开放至午夜) 这是我的密码 $currentTime = strtotime("01:14 pm"); $rangeStart = strtotime("11:00am"); $rangeEnd = strtotime("tomorrow 02:00 am"); if ($currentTime >= $rangeStart &

尝试获取每个门店的打开和关闭状态,如果在操作时间内,则返回打开,如果未返回关闭

例如:周一至周五:上午11:00至凌晨2:00(开放至午夜)

这是我的密码

$currentTime = strtotime("01:14 pm");       $rangeStart = strtotime("11:00am");         $rangeEnd = strtotime("tomorrow 02:00 am");
if ($currentTime >= $rangeStart && $currentTime <= $rangeEnd) {
   echo 'in range';         
} else {
        echo 'not in range';        
}
$currentTime=strottime(“01:14 pm”)$rangeStart=标准时间(“上午11:00”)$rangeEnd=标准时间(“明天凌晨2:00”);

如果($currentTime>=$rangeStart&&$currentTime检查
$currentTime
是否小于
$rangeStart

如果为true,则将
$currentTime
增加一天

<?php
$currentTime = date('d-m-Y H:i', strtotime("01:14 am"));      
$rangeStart = date('d-m-Y H:i', strtotime("11:00 am"));         
$rangeEnd = date('d-m-Y H:i', strtotime("tomorrow 02:00 am"));

if($currentTime < $rangeStart){
    $currentTime = date('d-m-Y H:i', strtotime("tomorrow".date('H:i',strtotime($currentTime))));     
}


if ($currentTime >= $rangeStart && $currentTime <= $rangeEnd) {
    echo 'in range';         
} else {

    echo 'not in range';        

}
?>


假设今天是2017年1月4日。$currentTime将是2017年1月4日凌晨1点。您需要将$currentTime设置为strotTime(“明天凌晨1:00”);或者您可以将$currentTime与昨天的开盘和收盘时间进行比较。请解释您的answer@Thamaraiselvam如果当前时间小于开始时间,则检查当前时间;如果将当前时间增加到1天,则将其添加到回答中,这将有助于其他人在没有解释的情况下发布代码,这可能会导致混乱。如果使用所有场景,则让他检查此代码里奥斯:那么我可以肯定,但让他核实所有情况