如何使用PHP计算以小时和分钟为单位的日期差?

如何使用PHP计算以小时和分钟为单位的日期差?,php,math,date,operation,Php,Math,Date,Operation,我有这段代码,他计算了日期差,到目前为止还不错,但我有个问题,我想从低值中减去高值,然后在负数上显示值,这段代码会自动找到哪个数字更高,我不想要那个 $to_time = strtotime("2012-10-25 10:42:00"); $from_time = strtotime("2012-10-26 10:21:00"); echo round(abs($to_time - $from_time) / 60,2). " minute"; 试一试 试试这个 $to_time = strt

我有这段代码,他计算了日期差,到目前为止还不错,但我有个问题,我想从低值中减去高值,然后在负数上显示值,这段代码会自动找到哪个数字更高,我不想要那个

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";
试一试

试试这个

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(($to_time - $from_time)/60,2). " minute";
$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(($to_time - $from_time)/60,2). " minute";