Home  >  Article  >  Backend Development  >  PHP's detailed explanation of the number of weeks within a period of time when changing zones

PHP's detailed explanation of the number of weeks within a period of time when changing zones

小云云
小云云Original
2018-01-25 15:15:101093browse

This article mainly shares with you PHP's detailed explanation of the number of weeks within a period of time when changing zones. It mainly uses code examples to share with you. I hope it can help you.

function numweeka($starttime,$endtime){
$arr = array('0'=>0,'1'=>0,'2'=>0,'3'=>0,'4'=>0,'5'=>0,'6'=>0);
if($starttime-$endtime >= 0){
return '开始时间大于或等于结束时间';
}else if(date('Y-m-d',$starttime) == date('Y-m-d',$endtime)){
$arr[date('w',$starttime)] = 1;;
return $arr;
}else{
$n = ($endtime - $starttime)/(24*60*60);
if($n <= 7){
for($i = $starttime;$i<$endtime;$i = $i +(24*60*60)){
switch(date(&#39;w&#39;,$i)){
case 0:
$arr[0]++;
break;
case 1:
$arr[1]++;
break;
case 2:
$arr[2]++;
break;
case 3:
$arr[3]++;
break;
case 4:
$arr[4]++;
break;
case 5:
$arr[5]++;
break;
case 6:
$arr[6]++;
break;
}
}
return $arr;
}else{
$num = intval($n/7);
foreach($arr as $k => $v){
$arr[$k] = $num;
}
$a = date(&#39;w&#39;,$starttime);
$b = date(&#39;w&#39;,$endtime);
if($a != 0){
for($i =$a;$i<=6;$i++){
$arr[$i]++;
}
}
if($b != 6){
for($i = 0;$i<=$b;$i++){
$arr[$i]++;
}
}
return $arr;
}
}
}
$starttime = &#39;952041600&#39;;
$endtime = &#39;1457827199&#39;;
$dataa = numweeka($starttime,$endtime);

Related recommendations:

MySQL memory swap area caused a

php weekly data writing related problem code

Find the initial date and end date of the week if the year and week number are known in php

The above is the detailed content of PHP's detailed explanation of the number of weeks within a period of time when changing zones. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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