我正在用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
}发布于 2016-07-20 12:58:40
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希望这能解决你的问题。
发布于 2016-07-20 13:01:22
我已经创建了以下代码来检查当前时间是否大于其他时间。请检查此代码。
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';
}https://stackoverflow.com/questions/38472582
复制相似问题