- //year
- $year = date("Y");
- $beninTime = mktime(0,0,0,1,1,$year);
- $endTime = mktime(0 ,0,0,1,1,$year+1)-1;
- $weekArray = array();
- $isBegin = true;
- $forTime = 0;
- for ($time=$beninTime;$time<= $endTime;){
- $forTime++;
- $start = $end = 0;
- if($isBegin){
- //$nIndex==1 means Monday, $nIndex==7 means Sunday
- $nIndex = date( "N",$time);
- //$mulNum=1 means Monday is one day later,
- $mulNum = 0;
- switch ($nIndex){
- case 1: $mulNum =7; break;
- case 2 : $mulNum =6; break;
- case 3: $mulNum =5; break;
- case 4: $mulNum =4; break;
- case 5: $mulNum =3; break;
- case 6: $mulNum =2; break;
- case 7: $mulNum =1; break;
- }
- }else{
- //Week 1
- $mulNum = 7;
- }
- if($mulNum>2){
- $start = $time;
- / /Friday time
- $end = $time+($mulNum-2-1)*24*60*60;
- if($end>$endTime){
- $end = $endTime;
- }
- $weekArray[] = array(
- 'start'=>$start,
- 'end'=> $end,
- );
- if($end>=$endTime){
- break;
- }
- }
- $time += $mulNum *24*60*60;
- $isBegin = false;
- }
- echo $forTime.'
';
- foreach ($weekArray as $week){
- echo date("Y-m-d",$week[ 'start'])."week".date("N",$week['start']).">>>>>>".date("Y-m-d",$week[' end'])."week".date("N",$week['end']).'
';
- }
- ?>
Copy code
|