그래서, 나는 다음과 같은 것이있는 API에 의해 반환되는 한 :PHP에서 시간을 빼는 방법은 무엇입니까?
<startTime>2011-04-12T01:28:40.000Z</startTime>
그것은 UTC/루어 형식입니다. PHP에서 타임 스탬프가 경과 된 후 경과 시간 (초)을 얻으려면 어떻게해야합니까?
모든 포인터 주셔서 감사합니다!
그래서, 나는 다음과 같은 것이있는 API에 의해 반환되는 한 :PHP에서 시간을 빼는 방법은 무엇입니까?
<startTime>2011-04-12T01:28:40.000Z</startTime>
그것은 UTC/루어 형식입니다. PHP에서 타임 스탬프가 경과 된 후 경과 시간 (초)을 얻으려면 어떻게해야합니까?
모든 포인터 주셔서 감사합니다!
$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');
'$ now = new DateTime (null, 새 DateTimeZone ('UTC')); '은 서버의 현재 시간대가 UTC가 아닌 경우 시간 차이가 거의 없도록 보장합니다. –
또는
$now = time();
$zulu = strtotime('2011-04-12T01:28:40.000Z');
$difference = $now - $zulul
$elapsed = time() - strtotime ($startTime);
체크 아웃 한 strtotime (http://us.php.net/manual/en/function.strtotime.php) 및 시간 함수 (http://us.php.net/manual/en/function.time.php을). 기본적으로 타임 스탬프를 정수로 변환 한 다음 현재 시간에서 뺍니다.
가능한 복제본 : http://stackoverflow.com/questions/3642652/get-current-date-and-date-after-two-months-in-php/3642658#3642658 –