我目前正在使用 Gravity Forms 插件,它设置为限制每天、每周、每月和每年的表单条目;不幸的是,我需要按小时计算。这是我正在编辑的原始代码:
private static function get_limit_period_dates($period){
if(empty($period))
return array("start_date" => null, "end_date" => null);
switch($period){
case "day" :
return array(
"start_date" => gmdate("Y-m-d"),
"end_date" => gmdate("Y-m-d 23:59:59"));
break;
case "week" :
return array(
"start_date" => gmdate("Y-m-d", strtotime("Monday this week")),
"end_date" => gmdate("Y-m-d 23:59:59", strtotime("next Sunday")));
break;
case "month" :
$month_start = gmdate("Y-m-1");
return array(
"start_date" => $month_start,
"end_date" => gmdate("Y-m-d H:i:s", strtotime("{$month_start} +1 month -1 second")));
break;
case "year" :
return array(
"start_date" => gmdate("Y-1-1"),
"end_date" => gmdate("Y-12-31 23:59:59"));
break;
}
}
我尝试了以下代码,我认为从 0 分 0 秒开始,然后添加一个小时就可以了,但它不起作用:
case "hour" :
return array(
"start_date" => gmdate("H:00:00"),
"end_date" => gmdate("H:i:s", strtotime("+1 hour")));
break;
我从未使用过 gmdate 函数,所以如果有人愿意简要解释我所缺少的内容,我很想了解这一点。谢谢!