This article mainly shares with you how PHP calculates whether two time periods overlap. It is mainly shared with you in the form of code. I hope it can help you.
/** * PHP计算两个时间段是否有交集(边界重叠不算) * * @param string $beginTime1 开始时间1 * @param string $endTime1 结束时间1 * @param string $beginTime2 开始时间2 * @param string $endTime2 结束时间2 * @return bool */function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') { $status = $beginTime2 - $beginTime1; if ($status > 0) { $status2 = $beginTime2 - $endTime1; if ($status2 >= 0) { return false; } else { return true; } } else { $status2 = $endTime2 - $beginTime1; if ($status2 > 0) { return true; } else { return false; } } }
/** * PHP计算两个时间段是否有交集(边界重叠不算) * * @param string $beginTime1 开始时间1 * @param string $endTime1 结束时间1 * @param string $beginTime2 开始时间2 * @param string $endTime2 结束时间2 * @return bool */function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') { $status = $beginTime2 - $beginTime1; if ($status > 0) { $status2 = $beginTime2 - $endTime1; if ($status2 >= 0) { return false; } else { return true; } } else { $status2 = $endTime2 - $beginTime1; if ($status2 > 0) { return true; } else { return false; } } }
Related recommendations:
php function to compare whether there is an intersection between time periods
The above is the detailed content of How to calculate whether two time periods intersect in PHP. For more information, please follow other related articles on the PHP Chinese website!