我发现了这个php代码credit to creator并希望以不同的方式实现它:
目标是让代码自动将以下语句调整为每月的第二个星期六,从现在到永远:
下一次会员大会:星期六、月、日、年、上午11:00至中午。
如:“2011年2月12日,星期六,上午11点到中午。”
我不是PHP大师,有人可以编辑它吗?

<?php

     function nextMeeting($nextMonth = false) {

     $day=date("j");
     $month=date("n");
     $year=date("Y");

     if ($nextMonth) {
             $day=1;
             if ($month == 12) {
                     $month=1;
                     $year++;
             } else {
                     $month++;
             }
     }

     $dayofweek=date("w");
     $firstOfMonth=date("w",mktime(0, 0, 0, $month , 1, $year ));


     // figure out what date is the second Saturday of the month
     if ( $firstOfMonth > 0 ) {
             $firstSunday= 8 - $firstOfMonth;
     } else {
             $firstSunday= 1;
     }

     $firstSundayDate=date("D",mktime(0, 0, 0, $month ,
     $firstSunday, $year));

     // figure out what date the third monday of the month is
     if ( $firstOfMonth > 1) {
             $offSet = 8 - $firstOfMonth;
     } elseif ( $firstOfMonth == 0 ) {
             $offSet=1;
     } else {
             $offSet=0;
     }
     $thirdMonday= 15 + $offSet;
     $thirdMondayDate=date("D",mktime(0, 0, 0, $month ,
     $thirdMonday, $year));

     // lets see which of these dates now applies
     if ($day <= $firstSunday) {
             // we didn't miss the first meeting
             $nextMeeting=$firstSunday;
             $nextMeetingDate=mktime(0, 0, 0, $month ,
             $nextMeeting, $year);
     } elseif ( ($day > $firstSunday) && ($day <= $thirdMonday) ) {
             // we missed the first meeting of the month, but can still make the second
             $nextMeeting=$thirdMonday;
             $nextMeetingDate=mktime(0, 0, 0, $month ,
             $nextMeeting, $year);
     } else {
             // we need to wait until next month
             $nextMeetingDate=nextMeeting(1);
             $nextMeeting=nextMeeting(1);
     }

     return $nextMeetingDate;

     }

     $meeting=nextMeeting();

     echo "Next membership meeting is on " . date('l dS \of F Y', $meeting);

     ?>

最佳答案

不如你省下5000行试试这个

<?
echo date('Y-m-d', strtotime('second saturday of february 2011'));

编辑
好吧,我在评论里撒了谎,我会帮你写的。
<?

$now=date("U");
$monthyear=date("F Y");
$secondsat=date('U', strtotime($monthyear.' second saturday'));
if ($now>$secondsat) {
    $monthyear=date("F Y", "next month");
    $secondsat=date('U', strtotime($monthyear.' second saturday'));
}

echo date("m/d/Y",$secondsat);

09-18 04:48