Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何获得从开始时间到结束时间的总小时数。
$start_time = '11:00:00 PM'; // as of 07/08/2013 $end_time = '01:00:00 AM'; // as of 08/08/2013
那么输出应该是:
$total = '02:00:00'; // 12 hour format
您可以将日期字符串转换为时间值,然后减去以获得两者之间的秒数差,然后只需除以 3600 即可获得小时数差:
$t1 = strtotime('2013-08-07 23:00:00'); $t2 = strtotime('2013-08-08 01:00:00'); $differenceInSeconds = $t2 - $t1; $differenceInHours = $differenceInSeconds / 3600;