时间很令人困惑... 如何在php中计算从PM到AM经过的时间?
例如:22:00:00(晚上10点)
到 02:00:00(凌晨2点)
应该返回 04小时
,但是我的代码返回了-08小时
function hours_elapsed()
{
$timestart = strtotime("22:00:00");
$timestop = strtotime("02:00:00");
$time_diff = $timestop - $timestart; //time difference
return gmdate("h", $total_hours);
}
很明显这段代码使用24小时制进行计算,所以当然会返回-08
。但是如果没有24小时的限制,当时间跨越午夜时,如何计算经过的时间呢?
TIME
的列中的时间,格式始终为 xx:xx:xx。 - CyberJunkie