【发布时间】:2017-08-11 08:06:12
【问题描述】:
我需要检查当前时间是否在范围内
these r restaurant open timings ,timings can be like open now till next morning or closed for sometime same day and open next half same day till next day or midnight
examples
Case1: 10:00 01:00
Case2: 10:00 23:59
Case3: 10:00 00:00
Case4: 23:59 05:00
Case5: 08:35 15:30 && 17:30 02:00
Case6: 10:00 15:00 && 17:00 00:00
必须检查所有情况
if((strtotime($s)<=strtotime($myTime)) && (strtotime($e)>=strtotime($myTime)))
{$open =1;}
if($e=="00:00")
{ if((strtotime($s)<=strtotime($myTime))&& (strtotime($myTime)>=strtotime("00:00")))
{$open =1;}}
这在我出错的地方不起作用
【问题讨论】:
-
第一种情况,第二行是次日还是9小时前的同一天?
-
我推荐使用 DateTime 对象。将您的“案例”存储在 DateTime 对象中并将它们与当前日期进行比较。有关示例,请参阅stackoverflow.com/questions/961074/…。
-
@131 不同的日子不同的例子 5/6 可以是一整天的时间
-
@user1915746 问题是我必须将范围与当前时间进行比较
-
@hir:我发布了一个示例作为答案。