两次之间是时间吗?

mel*_*oon 8 php

我想要做的(例如)是在星期三,晚上8点到凌晨2点之间更改我的网站徽标.技术上凌晨2点是周四早上.那么我如何检查当前时间是否在周三晚上8点到凌晨2点之间?

Sav*_*man 15

好吧,甚至更容易:

$current_time = strtotime('now');
if ($current_time > strtotime('wednesday this week 8:00pm') && $current_time < strtotime('thursday this week 2:00am')) {
    // Special logo
}
Run Code Online (Sandbox Code Playgroud)


zer*_*kms 7

更换strtotime(...)东西time()以处理当前时间.

$date = strtotime('2011-03-24 01:00:00');

if ((date('w', $date) == 3 && date('H', $date) >= 20) ||
    (date('w', $date) == 4 && date('H', $date) <= 1)) {
    echo "it's time to change logo";
} else {
    echo 'hello world';
}
Run Code Online (Sandbox Code Playgroud)