計算兩個Unix時間戳之間的差異我有計算兩個時間戳之間的差的函數,錯誤在PHP
public static function getDuration($from, $to) {
$duration = $to - $from;
return $duration;
}
但根據需要,這是行不通的。 例如,如果我傳球,
$difference = getDuration(strtotime('19-07-2012 23:00:00'), strtotime('20-07-2012 4:45:00'));
echo $difference/3600;
它返回的5.75 5.45代替,當轉換成小時。
這個結果是正確的5 + 0.75 * 60 = 5h 45m – 2012-07-20 07:25:46
學習基本的小數運算?只是一種可能的解決方 – ErikE 2012-07-20 07:26:49
@ErikE耶!現在我知道了:)謝謝你! – 2012-07-20 07:27:39