<?php
/**
* 计算时间间隔
*/
$start = new DateTime('2015-1-11 8:04:00');
$end = new DateTime('2019-8-31 9:30:10');
$interval = $start->diff($end);
echo $interval->format('%Y Years %m Months %d Days, %h Hours %i minutes %s Seconds.');
//04 Years 7 Months 20 Days, 1 Hours 26 minutes 10 Seconds.
版本要求:
PHP 5 >= 5.2.0
此版本及之后 Datetime 类和相关函数作为PHP核心发布,无需额外安装。