PHP的第二个星期六月功能 [英] Second Saturday of Month Function in PHP

查看:184
本文介绍了PHP的第二个星期六月功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个PHP代码信用到创建者,并希望实现它有一种不同的方式:

I found this PHP code credit to creator and want to implement it a different way:

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

The goal is to have the code automatically adjust the following statement to be the second Saturday of every month from now until eternity:



下一个会员资格会议:星期六, MONTH,DAY,YEAR ,上午11点至中午。


Next membership meeting: Saturday, MONTH, DAY, YEAR, 11 a.m. to noon.

如:星期六, 2011年2月12日,上午11点至中午。

As in: "Saturday, February 12, 2011, 11 a.m. to noon."

我不是PHP大师,有人可以编辑它工作吗?

I am no PHP guru, can someone kindly edit it to work?

<?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行, / p>

How about you save about 5000 lines and try this

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

编辑

好的,我在评论中撒谎,我会为你写。

Ok, I lied in the comments, I will write it for you.

<?

$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);

这篇关于PHP的第二个星期六月功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆