php中月份以星期为单位,PHP的月份第二个星期六

我发现这个PHP代码

credit to creator并希望以不同的方式实现它:

目标是让代码自动将以下语句调整为从现在起到永恒的每个月的第二个星期六:

下次会员会议:周六,每年,每年,上午11点至中午.

如:“2011年2月12日星期六,上午11点到中午.”

我不是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);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值