[英]How do I subtract time in PHP?
所以,我有一个API返回以下内容:
<startTime>2011-04-12T01:28:40.000Z</startTime>
它是UTC / Zulu格式。 从PHP中的时间戳开始,我将如何获得经过的时间(以秒为单位)?
感谢您的任何指示!
$now = new DateTime;
$zulu = new DateTime('2011-04-12T01:28:40.000Z');
$difference = $now->diff($zulu);
> = PHP 5.3支持diff()
。
否则,您可以使用time()
和strtotime()
。
$difference = time() - strtotime('2011-04-12T01:28:40.000Z');
要么
$now = time();
$zulu = strtotime('2011-04-12T01:28:40.000Z');
$difference = $now - $zulul
查看strtotime( http://us.php.net/manual/en/function.strtotime.php )和时间函数( http://us.php.net/manual/en/function.time.php )。 基本上,您将时间戳转换为整数,然后从当前时间减去它。
$elapsed = time () - strtotime ( $startTime);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.