如何使用php获取给定月份中一周的第一天和最后一天

时间:2015-05-22 04:09:33

标签: php

如何使用php获取给定月份中一周的第一天和最后一天。我试图通过谷歌搜索得到答案,但没有实现得到它。请帮我任何身体。我会为他而战。

1 个答案:

答案 0 :(得分:0)

嗨,每个人都有一些我如何得到解决方案,下面给出。

$ fstSunday = date(" dF-Y",strtotime("&#34的第一个星期日; .date(' M')。"& #34; .date(' Y&#39)。"&#34));         $ weekArray = getfstlastdayOfWeekofmonth($ fstSunday);                 回声'

';
                print_r( $weekArray);

function getfstlastdayOfWeekofmonth($paramFstSundayofMonth) { $fstSunday = $paramFstSundayofMonth; //echo 'last date of the week-'.$oneWeekLater = date('d-m-Y', strtotime('+1 week',strtotime($fstSunday))); $countMnth = date("t",strtotime($fstSunday)); $dayOfmonth = date("d",strtotime($fstSunday)); if($countMnth==31 && $dayOfmonth <= 3) $countmonth = 5; else $countmonth = 4; $weekArray = array(); for($i=0;$i<$countmonth;$i++) { $oneWeekLater = date('d-F-Y', strtotime('+1 week',strtotime($fstSunday)-1)); $weekArray[] = array('fstdayWeekOfmonth'=> $fstSunday,'lastDayWeekOfmonth'=>$oneWeekLater) ; $fstSunday = date('d-F-Y', strtotime('+1 week',strtotime($fstSunday))); } // echo '<pre>'; return $weekArray; }