找到差异秒[重复]

This question already has an answer here:

date_default_timezone_set('America/New_York');

$search_date = '2012-12-19 13:22:00';
$right_now = date('Y-m-d H:i:s');
$search_date = new DateTime($search_date);
$right_now = new DateTime($right_now);
$interval = $search_date->diff($right_now);
echo $interval->format('%R%s seconds');

This displays how many seconds are different between the search date and right now.

I would expect it to return more than a two digit value because there is more than a 99 second difference between the two dates, so I am not sure what I am doing wrong.

</div>

Alternatively, with very little change to your original code:-

date_default_timezone_set('America/New_York');

$search_date = new DateTime('2012-12-19 13:22:00');
$right_now = new DateTime();
$seconds = $right_now->getTimestamp() - $search_date->getTimestamp();