我需要做具体的 CSS 如果是在工作时间之外,如果是银行假期?

I need to do specific CSS if its outside working hours and if its a bank holiday?

我的网站上有一个实时聊天 link,我只需要在特定时间显示它,即:

周一至周五上午 8 点至晚上 8 点,银行假日除外。

我想通过基于时间的方式隐藏它CSS?或类似的东西。

我在想,因为我正在使用 WordPress,使用一些 PHP 代码来实现这个 CSS?我想我必须用 strtotime 函数做点什么。

您可以通过 php add/dont 添加 css class,这将 showing/disabling 聊天。 像这样:

Css:

.hidden{display:none;}

HTML + PHP

$bankholidays = [1225, 1226]; //array of dates in format "md" (25.12., 26.12.)

<div class="<?php if((date('N') > 5) || (date('H') < 8) || (date('H') > 20) || in_array(date("md"), $bankholidays)) echo 'hidden'; ?>"> <!-- chat --> </div>

解释:

(date('N') > 5)
date('N') - numeric representation of the day of the week (monday - 1 ..., saturday -6, sunday 7)

(date('H') < 8) || (date('H') > 20)
date('H') - 24-hour format of an hour with leading zeros (so hide before 8AM and after 8PM)

in_array(date('md'), $bankholidays)
date("md") - numeric representation of date in year in format mmdd so 0101..1231