以下是如何以一种很酷的方式做到这一点,特别感谢strtotime的
relative formats.
原文链接:https://www.f2er.com/php/138080.html$friday = strtotime('Next Friday',time()); $saturday = strtotime('Next Saturday',time()); $friday = strtotime('+1 Week',$friday); $saturday = strtotime('+1 Week',$saturday);
当然你应该调整它以完全按照自己的意愿行事,但这与我试图做的不同.
另请注意,strtotime会为您提供时间戳.要找出使用日期:
date('Y-m-d',$friday)
另一件需要知道的是Next< dayofweek>将您的当前日期从搜索中排除,因此如果您还想要包含当天,您可以这样做:
$friday = strtotime('Next Friday',strtotime('-1 Day',time()));
这是一个完整的工作脚本,完全符合您的要求.
<?PHP // prevent multiple calls by retrieving time once // $now = time(); $aYearLater = strtotime('+1 Year',$now); // fill this with dates // $allDates = Array(); // init with next friday and saturday // $friday = strtotime('Next Friday',$now)); $saturday = strtotime('Next Saturday',$now)); // keep adding days untill a year has passed // while(1){ if($friday > $aYearLater) break 1; $allDates[] = date('Y-m-d',$friday); if($saturday > $aYearLater) break 1; $allDates[] = date('Y-m-d',$saturday); $friday = strtotime('+1 Week',$friday); $saturday = strtotime('+1 Week',$saturday); } //XXX: debug var_dump($allDates); ?>
祝你好运,Alin