这是我下面要获取的代码。但是这个代码将使下午6点前的一小时无效,哪一分钟超过30,我该怎么做
如果今天是"3",并且今天的时间仍然在下午6:30之前,则if条件将工作
我当前的代码:
if( ($today=="3") && ($today_hour < "18") && ($today_min < "30") )
{
}
如果小时实际上是6,则只应检查分钟。将您的条件更改为:
if ($today == 3 && ($today_hour < 18 || ($today_hour == 18 && $today_min < 30))) {
// Do stuff
}
或者更容易阅读:
$beforeTime = $today_hour < 18 || ($today_hour == 18 && $today_min < 30);
if ($today == 3 && $beforeTime) {
// Do stuff
}
请确保也使用数字,因为当数字的数量不同时,对它们进行字符串比较会导致意外的结果。
试试这个,它会帮助你:
if ((date('d') == "03") && (date('H') < "18:30")) {
$condition = true;
}
H=一小时的24小时格式(00至23)