[英]How to get the total hr from start time to end time using 12 Hour Format in php
[英]How to get the total hour from starting time to end time in php
我如何獲得從開始時間到結束時間的總小時數。
$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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.