/**
* functionï¼è®¡ç®ä¸¤ä¸ªæ¥æç¸éå¤å°å¹´ï¼å¤å°æï¼å¤å°å¤©
* param string $date1[æ ¼å¼å¦ï¼2011-11-5]
* param string $date2[æ ¼å¼å¦ï¼2012-12-01]
* return array array('å¹´','æ','æ¥');
*/
function diffDate($date1,$date2)
{
$datetime1 = new \DateTime($date1);
$datetime2 = new \DateTime($date2);
$interval = $datetime1->diff($datetime2);
$time['y'] = $interval->format('%Y');
$time['m'] = $interval->format('%m');
$time['d'] = $interval->format('%d');
$time['h'] = $interval->format('%H');
$time['i'] = $interval->format('%i');
$time['s'] = $interval->format('%s');
$time['a'] = $interval->format('%a'); // 两个æ¶é´ç¸å·®æ»å¤©æ°
return $time;
}
# 使ç¨å®ä¾
$sss = diffDate('2015-12-25 12:30:30', '2015-12-26 15:00:00');
print_r($sss);
# è¾åº
Array
(
[y] => 00
[m] => 0
[d] => 1
[h] => 02
[i] => 29
[s] => 30
[a] => 1
)
温馨提示:内容为网友见解,仅供参考