我在PHP中进行的时间计算大于时间计算,在以下情况下运行良好:
$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";
}
但如果我改变时间就像这样,在这种情况下,结果是&#34; NO&#34;,任何人都可以解释原因吗?:
$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
}
答案 0 :(得分:2)
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
希望这能解决您的问题。
答案 1 :(得分:0)
我创建了以下代码来检查当前时间是否大于其他时间。请检查此代码。
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';
}