Reputation: 33
So, I have the following being returned by an API:
<startTime>2011-04-12T01:28:40.000Z</startTime>
It's in UTC/Zulu format. How would I go about getting the time elapsed (in seconds) since that timestamp in PHP?
Thanks for any pointers!
Upvotes: 3
Views: 7090
Reputation: 490143
$now = new DateTime;
$zulu = new DateTime('2011-04-12T01:28:40.000Z');
$difference = $now->diff($zulu);
diff()
is supported in >= PHP 5.3.
Otherwise, you can use time()
and strtotime()
.
$difference = time() - strtotime('2011-04-12T01:28:40.000Z');
Upvotes: 8
Reputation: 25295
Check out the strtotime (http://us.php.net/manual/en/function.strtotime.php) and time functions (http://us.php.net/manual/en/function.time.php). Basically you would convert your timestamp to an integer, then subtract it from the current time.
Upvotes: 1
Reputation: 5395
Or
$now = time();
$zulu = strtotime('2011-04-12T01:28:40.000Z');
$difference = $now - $zulul
Upvotes: 1