以小时,分钟和秒为单位获取时差

问题描述:

我有两个日期,

$expiry_time = strtotime('comming from database');
$current_date = strtotime(date('Y-m-d H:i:s'));
$time_diff = ($expiry_time-$current_date)/(3600);

在这里, $ time_diff 给我带来的不同在几个小时内。例如。 5.67。但是,我想要小时,分钟和秒格式。我该如何实现?
谢谢。

Here, $time_diff will give me difference in hours. eg. 5.67. But, I want it in hours, minute and second format. How can I achieve this? Thanks.

DateTime() DateInterval()

$expiry_time = new DateTime($row['fromdb']);
$current_date = new DateTime();
$diff = $expiry_time->diff($current_time);
echo $diff->format('%H:%I:%S');