如何使用php中的12小时格式获取从开始时间到结束时间的总小时数


How to get the total hr from start time to end time using 12 Hour Format in php

如何使用"HH:mm:ss"格式从两个给定时间中获得总小时数

这是我的代码:

   $start = 01:00:00 PM;
   $end = 02:00:00 PM;

预期输出:

   $total = 1;

您可以这样尝试:

$start = new DateTime('01:00:00 PM');
$end = new DateTime('02:00:00 PM');
$diff = $start->diff($end);
echo $diff->format('%H'); 

您可以获得更多信息:http://in1.php.net/manual/en/datetime.diff.php