2011-04-13 3 views
2

그래서, 나는 다음과 같은 것이있는 API에 의해 반환되는 한 :PHP에서 시간을 빼는 방법은 무엇입니까?

<startTime>2011-04-12T01:28:40.000Z</startTime> 

그것은 UTC/루어 형식입니다. PHP에서 타임 스탬프가 경과 된 후 경과 시간 (초)을 얻으려면 어떻게해야합니까?

모든 포인터 주셔서 감사합니다!

+0

가능한 복제본 : http://stackoverflow.com/questions/3642652/get-current-date-and-date-after-two-months-in-php/3642658#3642658 –

답변

7
$now = new DateTime; 

$zulu = new DateTime('2011-04-12T01:28:40.000Z'); 

$difference = $now->diff($zulu); 

diff()은 PHP 5.3 이상에서 지원됩니다.

그렇지 않으면 time()strtotime()을 사용할 수 있습니다.

$difference = time() - strtotime('2011-04-12T01:28:40.000Z'); 
+0

'$ now = new DateTime (null, 새 DateTimeZone ('UTC')); '은 서버의 현재 시간대가 UTC가 아닌 경우 시간 차이가 거의 없도록 보장합니다. –

1

또는

$now = time(); 

$zulu = strtotime('2011-04-12T01:28:40.000Z'); 

$difference = $now - $zulul 
0
$elapsed = time() - strtotime ($startTime); 
관련 문제