PHP比较时间戳和实时的差异

adi*_*uuu 3 php datetime

我想比较两个时间戳和基数60或10的时间之间的差异.更准确地说,如果timestamp1-timestamp2比x小时和y秒更长(或没有).

我正在使用DateTime和DateInterval类,但没有这样的功能,我找不到干净的解决方案.

谢谢

Shi*_*dim 8

$time1 = new DateTime("2011-01-26 01:13:30"); // string date
$time2 = new DateTime();
$time2->setTimestamp(1327560334); // timestamps,  it can be string date too.
$interval =  $time2->diff($time1);
echo $interval->format("%H hours %i minutes %s seconds");
Run Code Online (Sandbox Code Playgroud)

产量

11 hours 32 minutes 4 seconds
Run Code Online (Sandbox Code Playgroud)