当前位置:Gxlcms > PHP教程 > 计算一年内周一到周五的间隔区间

计算一年内周一到周五的间隔区间

时间:2021-07-01 10:21:17 帮助过:44人阅读

<无详细内容>
  1. //年
  2. $year = date("Y");
  3. $beninTime = mktime(0,0,0,1,1,$year);
  4. $endTime = mktime(0,0,0,1,1,$year+1)-1;
  5. $weekArray = array();
  6. $isBegin = true;
  7. $forTime = 0;
  8. for ($time=$beninTime;$time<=$endTime;){
  9. $forTime++;
  10. $start = $end = 0;
  11. if($isBegin){
  12. //$nIndex==1表示星期一,$nIndex==7表示星期日
  13. $nIndex = date("N",$time);
  14. //$mulNum=1表示过1天就是星期一,
  15. $mulNum = 0;
  16. switch ($nIndex){
  17. case 1: $mulNum =7; break;
  18. case 2: $mulNum =6; break;
  19. case 3: $mulNum =5; break;
  20. case 4: $mulNum =4; break;
  21. case 5: $mulNum =3; break;
  22. case 6: $mulNum =2; break;
  23. case 7: $mulNum =1; break;
  24. }
  25. }else{
  26. //周1
  27. $mulNum = 7;
  28. }
  29. if($mulNum>2){
  30. $start = $time;
  31. //周五时间
  32. $end = $time+($mulNum-2-1)*24*60*60;
  33. if($end>$endTime){
  34. $end = $endTime;
  35. }
  36. $weekArray[] = array(
  37. 'start'=>$start,
  38. 'end'=> $end,
  39. );
  40. if($end>=$endTime){
  41. break;
  42. }
  43. }
  44. $time += $mulNum*24*60*60;
  45. $isBegin = false;
  46. }
  47. echo $forTime.'
    ';
  48. foreach ($weekArray as $week){
  49. echo date("Y-m-d",$week['start'])."星期".date("N",$week['start']).">>>>>>".date("Y-m-d",$week['end'])."星期".date("N",$week['end']).'
    ';
  50. }
  51. ?>

人气教程排行