以小时,分钟和秒为单位获取时差 [英] get time difference in hours minutes and seconds
本文介绍了以小时,分钟和秒为单位获取时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个日期,
$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');
这篇关于以小时,分钟和秒为单位获取时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文