计算所选时间大于或小于当前时间


calculate selected time is greater than or less than current time

Iam在php中进行genreal大于小于时间的计算,它在以下情况下运行良好:

$a = "10:00am"; // say selected time1
$b = "10:15am"; //say current time
$c = "10:30am"; // say selected time2
if($b>$a && $b<$c){
 echo "YES"; // This is the result, which is correct
}else{
echo "NO";
}

但如果我这样改变时间,在这种情况下,结果是"否",有人能解释为什么吗?:

    $a = "9:00am"; // say selected time1
    $b = "10:00am"; //say current time
    $c = "11:30am"; // say selected time2
    if($b>$a && $b<$c){
     echo "YES";
    }else{
    echo "NO"; // This is the result, which is not correct
    }

strtotime——将任何英文文本日期时间描述解析为Unix时间戳

$a = strtotime("9:00am"); // say selected time1
$b = strtotime("10:00am"); //say current time
$c = strtotime("11:30am"); // say selected time2
if($b>$a && $b<$c){
 echo "YES";
}else{
echo "NO"; // This is the result, which is not correct
}

输出:

YES

希望这能解决你的问题。

我创建了以下代码来检查当前时间是否大于其他时间。请检查此代码。

if(strtotime(date('H:i:s')) > strtotime(date('10:00:00'))){
  echo 'Greater than 10 AM';
}
else{
  echo 'Less than 10 AM';
}

否则,您可以使用此代码,用于24小时格式

if(date("G") >= 10)      
{
  echo 'current time is greater than 10:00 AM';
}