繁体   English   中英

在php中找到两次之间的小时差不起作用

[英]finding hour difference between two times in php not working

我的 sql 表中有 2 次,例如 02:56:07pm 和 03:56:14pm,所以我将其转换为:

 $time1 = date("G:i:s", strtotime($row['timein'])); $time2 = date("G:i:s", strtotime($row['timeout']));

这给了我两次 14:56:07 和 15:56:14

现在我试图找到这两次之间的小时数差异,我喜欢以下内容:

 $difference = round(abs($time2 - $time1) / 3600,2); echo $difference;

但这里得到 0 作为答案,任何人都可以告诉我如何解决它,提前致谢

这对我有用:

使用strtotime将日期/时间字符串转换为 Unix 时间戳(例如 163612416703)。 现在可以对时间进行计算。

$time1 = strtotime('02:56:07pm');
$time2 = strtotime('05:56:14pm');

$difference = date('H:i:s', ($time2 - $time1));
echo $difference; //03:00:07

玩弄格式等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM