【发布时间】:2011-04-22 19:57:15
【问题描述】:
我有这样的约会:
// just a example date
$time_in_the_future_start = date('H:i', time()+60*60*24*7);
$time_in_the_future_end = date('H:i', time()+60*60*24*7+480);
$now = date('H:i', time());
如何知道当前时间是否在$time_in_the_future的时间之内?
例如如果
$time_in_the_future_start = 21:30;
$time_in_the_future_end = 0:30;
和
$now = 22:07
这将是一场比赛。
编辑:
澄清一下,$time_in_the_future 是一个反复发生的事件,日期在过去或将来。我只需要匹配小时+分钟,而不是日期的其余部分...基本上我只想比较一天中的时间
【问题讨论】:
-
你不能只获取所有三个
time()值然后检查$start <= $now && $end >= $now吗? -
根据您的示例:
start=21:30和end=00:30不是同一天的时间。您应该在此计算中包括天数,或者只是使用下面我的答案中的函数。它不关心日期,但仍然在end<start的计算中添加+1 day。