每周某些时间/天显示按钮


Show button certain times/days every week

我需要在我的网站上显示一个按钮,只有某些天/时间

为例:


Sunday - 8am-8pm
星期一- Dont Show
星期二- 7pm-9pm
星期三- 4pm-11pm

依此类推(每周重复)

我怎样才能做到这一点?(使用javascript或php)

这是php中的一种方法:

$show_times = array(
    array('sunday 8am', 'sunday 8pm'),
    array('tuesday 7pm', 'tuesday 9pm'),
    array('wednesday 4pm', 'wednesday 11pm')
);
$now = time();
$show = false;
foreach ($show_times as $time) {
    $from = strtotime($time[0]);
    $to = strtotime($time[1]);
    if ($now >= $from and $now <= $to) {
        $show = true;
        break;
    }
}
if ($show) {
    echo '<button>the button</button>';
}