는 PHP < 5.3 있기 때문에 DateInterval
클래스를 지원하지 않습니다 (이 작업을 수행 할 수있는 권리 방법입니다) DateTime::diff()
사용할 수 없습니다. 5.2.x에서 작동하려면이 작업을 수동으로 수행해야합니다.
수학은 실제로 매우 간단합니다 : 그것은 윤년을 고려하지 않기 때문에
// Get the difference between the two dates, in seconds
$diff = $future_date->format('U') - $now->format('U');
// Calculate the days component
$d = floor($diff/86400);
$diff %= 86400;
// Calculate the hours component
$h = floor($diff/3600);
$diff %= 3600;
// Calculate the minutes component
$m = floor($diff/60);
// Calculate the seconds component
$s = $diff % 60;
// $d, $h, $m and $s now contain the values you want, so you can just build a
// string from them
$str = "$d d, $h h, $m m, $s s";
그러나 큰 간격이, 부정확를 소개합니다. 즉, 몇 초 안에 끝날 수도 있지만 원래 형식 문자열에는 초 구성 요소가 포함되어 있지 않으므로이 작업을 수행하는 데 너무 많은 문제가 발생할 수 있습니다.
$future_date
에서 $now
을 뺄 필요가 있습니다. 그렇지 않으면 결과가 부정됩니다. 내가 시도 무엇
See it working
당신은 여기 댓글에 몇 가지 솔루션에 모습을 가질 수있다 : http://php.net/manual/en/function.date-diff.php –