本文介绍了如何在PHP中比较两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两次格式,如7:30:00和22:30:00存储在变量 $ resttimefrom
和 $ resttimeto
I had two times in the format like 7:30:00 and 22:30:00 stored in the variables $resttimefrom
and $resttimeto
respectively.
我想检查当前时间是否在这两个值之间。我正在检查这个代码
I want to check whether the current time is between these two values. I am checking this with the code
$time = date("G:i:s");
if ($time > $resttimefrom and $time < $resttimeto ){
$stat = "open";
} else {
$stat = "close";
}
但是我总是把$ stat作为关闭。可能会导致什么?
But I am always getting the $stat as Close. What may cause that?
推荐答案
正如上文所述,Shrapnel说,我正在通过将所有时间转换成几秒钟,然后比较与当前时间的总秒数
As Col. Shrapnel Said i am doing by converting all the time in to seconds and then compare it with current time's total seconds
这篇关于如何在PHP中比较两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!