用PHP计算两小时之间的差异 [英] Calculate difference between 2 times in hours in PHP

查看:100
本文介绍了用PHP计算两小时之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两次 -
例如 - 当前时间 - 08:24,日期是02/01/2013以dd / mm / yyyy格式
,我有另一个时间在13:46日期是2012年12月31日。那么,如何使用PHP计算出两小时之间的差距。 (即42.63小时)
提前感谢

I have two times - For eg- the current time - 08:24 and date is 02/01/2013 in dd/mm/yyyy format and I have another time at 13:46 and date is 31/12/2012 . So, how can I calculate the difference between the 2 times in hours using PHP. (i.e. 42.63 hours) Thanks in advance.

推荐答案

将它们转换为时间戳值,然后减去获取

Convert them both to timestamp values, and then subtract to get the difference in seconds.

$ts1 = strtotime(str_replace('/', '-', '02/01/2013 08:24'));
$ts2 = strtotime(str_replace('/', '-', '31/12/2012 13:46'));
$diff = abs($ts1 - $ts2) / 3600;

这篇关于用PHP计算两小时之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆