$list = $this->getBetweenDays($time1, $time2);//获取多天内的上班时间数组
$num = $this->getNum($list, $time1, $time2); //获取范围时间内的去除休息时间的时间戳
//根据列表获取跨天时间差
public function getNum($list, $time1, $time2)
{
$arr = [];
$i = 0;
$k = 0;
$num = 0;
$begin0000=strtotime(date('Y-m-d 00:00:00', $time1));
$begin1200=strtotime(date('Y-m-d 12:00:00', $time1));
$begin1330=strtotime(date('Y-m-d 13:30:00', $time1));
$begin1900=strtotime(date('Y-m-d 19:00:00', $time1));
$begin2000=strtotime(date('Y-m-d 20:00:00', $time1));
$begin2359=strtotime(date('Y-m-d 23:59:00', $time1))+60;
foreach ($list as $key => $value) {
if ($time2 >= $value[0] && $time2 <$value[1]){
$k = 1;
$arr[] = array($value[0], $time2);
continue;
}
if ($i == 1) {
$arr[] = array($value[0], $value[1]);
}
if ($time1 >= $value[0] && $time1 <$value[1]){
$i = 1;
$arr[] = array($time1, $value[1]);
}
if(($time1 >=$begin1200 && $time1 <$begin1330) ){
$i = 1;
}
if(($time1 >=$begin1900 && $time1 <$begin2000)){
$i = 1;
}
}
foreach ($arr as $key => $value) {
if($time2>$value[0] && $time1<$value[1]){
$num += $value[1] - $value[0];
//echo date('Y-m-d H:i:s', $value[0]).'-----'. date('Y-m-d H:i:s', $value[1]);
//echo '<br>';
}
}
//die;
if($time1<$begin1200 && $time1>$begin0000 && $time2<$begin1200 && $time2>$begin0000 ){
$num=$time2-$time1;
}
if($time1<$begin1900 && $time1>$begin1330 && $time2<$begin1900 && $time2>$begin1330 ){
$num=$time2-$time1;
}
if($time1<$begin2359 && $time1>$begin2000 && $time2<$begin2359 && $time2>$begin2000 ){
$num=$time2-$time1;
}
return $num;
}
//获取日期直接的天数
public function getDateRange($start, $end) {
$range = array();
for ($i = 0;strtotime($start . '+' . $i . ' days') <= strtotime($end);$i++) {
$time = strtotime($start . '+' . $i . ' days');
$range[] = date('Y-m-d', $time);
}
return $range;
}
//根据范围时间获取上班时间
public function getBetweenDays($day_start, $day_end)
{
$days = [];
$start=date('Y-m-d', $day_start);
$end=date('Y-m-d', $day_end);
$days=$this->getDateRange($start, $end);
$arr = [];
foreach ($days as $key => $value) {
$begin0000 = strtotime($value . ' 00:00:00');
$begin1200 = strtotime($value . ' 12:00:00');
$begin1330 = strtotime($value . ' 13:30:00');
$begin1900 = strtotime($value . ' 19:00:00');
$begin2000 = strtotime($value . ' 20:00:00');
$begin2359 = strtotime($value . ' 23:59:00')+60;
$arr[] = array($begin0000, $begin1200);
//$arr[]=array($begin1200,$begin1330);
$arr[] = array($begin1330, $begin1900);
//$arr[]=array($begin1900,$begin2000);
$arr[] = array($begin2000, $begin2359);
}
return $arr;
}