PHP实现获取某个月份周次信息的方法_PHP

WBOY
Release: 2016-05-30 08:47:08
Original
774 people have browsed it

本文实例讲述了PHP实现获取某个月份周次信息的方法。分享给大家供大家参考。具体如下:

<&#63;php
 function getMonthweeks($date){
 $ret=array();
  $stimestamp=strtotime($date);
  $mdays=date('t',$stimestamp);
  $msdate=date('Y-m-d',$stimestamp);
  $medate=date('Y-m-'.$mdays,$stimestamp);
 $etimestamp = strtotime($medate);
 //獲取第一周
 $zcsy=6-date('w',$stimestamp);//第一周去掉第一天還有幾天
 $zcs1=$msdate;
 $zce1=date('Y-m-d',strtotime("+$zcsy day",$stimestamp));
 $ret[1]="第1周".$zcs1.'~'.$zce1;
 //獲取中間周次
 $jzc=0;
 //獲得當前月份是6周次還是5周次
 $jzc0="";
 $jzc6="";
 for($i=$stimestamp; $i<=$etimestamp; $i+=86400){
 if(date('w', $i) == 0){$jzc0++;}
 if(date('w', $i) == 6){$jzc6++;}
 }
 if($jzc0==5 && $jzc6==5)
 {
 $jzc=5;
 }else{
 $jzc=4;
 }
 date_default_timezone_set('PRC');
 $t = strtotime('+1 monday '.$msdate);
 $n = 1;
 for($n=1; $n<$jzc; $n++) {
 $b = strtotime("+$n week -1 week", $t);
 $dsdate=date("Y-m-d", strtotime("-1 day", $b));
 $dedate=date("Y-m-d", strtotime("5 day", $b));
 $jzcz=$n+1;
 $ret[$jzcz]="第".$jzcz."周".$dsdate.'~'.$dedate;
 }
 //獲取最後一周
 $zcsy=date('w',$etimestamp);//最後一周是周幾日~六 0~6
 $zcs1=date('Y-m-d',strtotime("-$zcsy day",$etimestamp));
 $zce1=$medate;
 $jzcz=$jzc+1;
 $ret[$jzcz]="第".$jzcz."周".$zcs1.'~'.$zce1;
 return $ret;
}
$ret=getMonthweeks('2012-12-01');
for($i=0; $i<=count($ret); $i++) {
 echo @$ret[$i]."<br />";
}
&#63;>

Copy after login

运行结果如下:

第1周2012-12-01~2012-12-01
第2周2012-12-02~2012-12-08
第3周2012-12-09~2012-12-15
第4周2012-12-16~2012-12-22
第5周2012-12-23~2012-12-29
第6周2012-12-30~2012-12-31

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template