时间范围特殊情况下,我面临着这样的时间范围内的特殊情况的问题。我有一个决定时间是否在范围内的功能。在PHP
function check_time($start, $end){
$start = date('H:i', strtotime($start)); // ex: 11:00 AM
$end = date('H:i', strtotime($end)); // ex: 2:00 PM
// check the range
if (current_time('H:i') > $start && current_time('H:i') < $end) {
return true;
}
}
这适用于不同的情况,但如果结束时间通过午夜到第二天,它将失败。
for example, assume the current time is 3:00 PM
6:00 AM - 10:00 PM // true
1:00 PM - 9:00 PM // true
2:00 PM - 1:00 AM // false // should be true
2:00 PM - 2:00 AM // false // should be true
如何避免测试在这些特殊情况下失败,并且即使经过午夜也返回true?
使用完整的日期和时间而不是只是小时和分钟。 – Cfreak
何时传递开始和结束变量或在计算过程中? – user7834963
你需要在通过他们和他们比较日期和时间。 – Cfreak