计算一年内周一到周五的间隔区间
时间:2021-07-01 10:21:17
帮助过:44人阅读
<无详细内容>
- //年
- $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; 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{
- //周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'])."星期".date("N",$week['start']).">>>>>>".date("Y-m-d",$week['end'])."星期".date("N",$week['end']).'
'; - }
- ?>
|