目前我正在做类似以下的事情
if(date("H") > 23) {
if(date("H") < 24) {
if(date("i") < 10) {
if(date("i") < 20) {
//perform an action if it's between 11:10pm and 11:20pm
}
}
}
}
更快更清晰地执行此类if
陈述是什么?
答案 0 :(得分:3)
代码不是很少,但可能更容易阅读:
$now = new DateTime();
$early = new DateTime('23:10');
$late = new DateTime('23:20');
if ($now > $early && $now < $late) {
//perform an action if it's between 11:10pm and 11:20pm
}
答案 1 :(得分:0)
有很多方法可以做到这一点。这是一个。
$now = date('H:i');
$target1 = date('23:10');
$target2 = date('23:20');
if ($now > $target1 && $now < $target2)
{
// Do something
}