- //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 は月曜日、$nIndex==7 は日曜日を意味します
- $nIndex = date( " N",$time);
- //$mulNum=1 は月曜日が 1 日後であることを意味します,
- $mulNum = 0;
- switch ($nIndex){
- case 1: $mulNum =7; Break;
- case 2 : $ mulNum =6; ブレーク;
- ケース 3: $mulNum =5; ブレーク;
- ケース 5: $mulNum =3; ブレーク;
- ケース 7: $mulNum =1; Break;
- }
- }else{
- //第 1 週
- $mulNum = 7;
- }
- if($mulNum>2){
- $start = $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']).'
';
- }
- ?>
-
-
コードをコピー
|