时间:2021-07-01 10:21:17 帮助过:4人阅读
<?php /** +---------------------------------------------------------- * 功能:计算两个日期相差 年 月 日 +---------------------------------------------------------- * @param date $date1 起始日期 * @param date $date2 截止日期日期 +---------------------------------------------------------- * @return array +---------------------------------------------------------- */ function DiffDate($date1, $date2) { if (strtotime($date1) > strtotime($date2)) { $ymd = $date2; $date2 = $date1; $date1 = $ymd; } list($y1, $m1, $d1) = explode('-', $date1); list($y2, $m2, $d2) = explode('-', $date2); $y = $m = $d = $_m = 0; $math = ($y2 - $y1) * 12 + $m2 - $m1; $y = round($math / 12); $m = intval($math % 12); $d = (mktime(0, 0, 0, $m2, $d2, $y2) - mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; if ($d < 0) { $m -= 1; $d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); } $m < 0 && $y -= 1; return array($y, $m, $d); } ?>
http://www.bkjia.com/PHPjc/825387.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825387.htmlTechArticle在PHP程序中,很多时候都会遇到处理时间的问题,比如:判断用户在线了多长时间,共登录了多少天,两个帖子发布的时间差或者是不同操...