[英]How to get the total hr from start time to end time using 12 Hour Format in php
How can I get the total hour from two given time with "HH:mm:ss" format? 如何使用“ HH:mm:ss”格式从两个给定时间中获得总时数?
Here is my code: 这是我的代码:
$start = 01:00:00 PM;
$end = 02:00:00 PM;
Expected Output: 预期产量:
$total = 1;
You can try like this: 您可以这样尝试:
$start = new DateTime('01:00:00 PM');
$end = new DateTime('02:00:00 PM');
$diff = $start->diff($end);
echo $diff->format('%H');
You can get more info: http://in1.php.net/manual/en/datetime.diff.php 您可以获取更多信息: http : //in1.php.net/manual/en/datetime.diff.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.