PHP计算两个日期之间周末天数
小代码,随便写写,时间复杂度空间复杂度就不纠结了吧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public function getWeekendDays($fromDate,$toDate)
{
$start_z = date('z',strtotime($fromDate));
$end_z = date('z',strtotime($toDate));
$weeksOffset = ($end_z/7) - ($start_z/7);
$start_N = date('N', strtotime($fromDate));
$end_N = date('N',strtotime($toDate));
if(($start_N+$end_N)>10)
{
if($start_N>5)
$weeksOffset +=(5-$start_N)/2;
if($end_N>5)
$weeksOffset +=($end_N-5)/2;
}
return $weeksOffset*2;
}
近期评论