使用php获取两个时间/日期之间的差异?

jim*_*mbo 2 php

我想知道两个日期之间的分钟时间差,格式为dmY H:i(14-04-2009 12:15)使用php?

bra*_*fck 10

使用strtotime()将时间解析为时间戳,然后简单地从另一个中减去一个.

之后,您可以使用数学函数获得分钟数,天数等.

例如:

// $date1 and $date2 are given
// the difference is in seconds
$difference = strtotime($date1) - strtotime($date2);

// getting the difference in minutes
$difference_in_minutes = $difference / 60;
Run Code Online (Sandbox Code Playgroud)

参考: strtotime()