php比较小时H:i作为字符串

时间:2018-08-24 11:28:26

标签: php time

您如何看待该解决方案。

例如:

 $firstHour = '08:30';
 $secondHour = '12:30';
 $test = $firstHour >= $secondHour; // will be false
 $test2 = $secondHour >= $firstHour; //will be true

该解决方案有什么弱点吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试将转换时间转换为strtotime()

$firstHour = strtotime('08:30');
$secondHour = strtotime('12:30');

$test = $firstHour >= $secondHour; 
$test2 = $secondHour >= $firstHour;