嗨我有一個24小時時間格式的兩個變量,並且要計算工作小時數。但我得到計算在2 24小時時間格式中工作的小時數PHP
我使用PHP,這裏是我的代碼
$endtime = date('g:i A', strtotime($itInfo['endTime']));
$startTime = date('g:i A', strtotime($itInfo['startTime']));
$timeDiff = (strtotime($endtime) - strtotime($startTime))/60/60;
$total = strtotime($endtime) - strtotime($startTime);
$hours = floor($total/60/60);
$minutes = round(($total - ($hours * 60 * 60))/60);
echo "FROM ".$itInfo['startTime']." TO ".$itInfo['endTime']." (".$hours.'.'.$minutes."hours)";`
下面是從22:00輸出到03:00(-19.0hours),這是錯誤的輸出應該是消極和錯誤值5個小時。
你有這種格式YYYY-MM-DD HH時間:MM:SS? –
[計算PHP中2個日期之間的小時數]可能的重複(http://stackoverflow.com/questions/3108591/calculate-number-of-hours-between-2-dates-in-php) – Hytool
No. '把它保存爲這種格式的varchar HH:MM在24小時內 –