$start = "2015-01-01 10:00:00";
$end = "2015-05-05 12:06:06";
$x = strtotime($start);
$y = strtotime($end);
$z = abs($y - $x);
$days = floor($z/(60 * 60 * 24));
$years = floor($z/(365 * 60 * 60 * 24));
$months = floor(($z - $years * 365 * 60 * 60 * 24)/(30 * 60 * 60 * 24));
$days = floor(($z - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24)/(60 * 60 * 24));
$hours = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24)/(60 * 60));
$minuts = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60)/60);
$seconds = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minuts * 60));
輸出是:如何找到兩個日期之間的區別
4 month 4 days 1 hour 6 minute 6 seconds
預期成果是:
4 month 4 days 2 hour 6 minute 6 seconds
看看日期時間,對象和(日期時間 - >差異()](http://php.net/manual/en/datetime.diff.php)函數..順便說一下,小時差異是正確的...如果夏季/冬季時間considderation。 – Naruto