计算2个日期之间的差异我做错了什么?

I'm trying to calculate the difference between 2 dates: $now and $old to get -> how long as past since old datetime.

$current_date = time();
$old= new DateTime($dateTimeString);
$now= new DateTime($current_date);
$interval = $now->diff($old);

I was trying with these values: 2016-02-23 02:15:43 --- 2016-02-22 21:45:11 and the result was more than 14hours of difference. I print the result like this:

$interval->format('%i Hours ago.');
$interval->format('%d Days ago.');

What I am doing wrong please?

The problem is here:

$current_date = time();
$now = new DateTime($current_date);

The value returned by time() is the number of seconds since 1970-01-01 00:00:00 UTC. The DateTime constructor tries to interpret it as a date that uses one of the usual date formats, it fails and produces a DateTime objects initialized with 0 (i.e. 1970-01-01 00:00:00 UTC).

If you want to create a new DateTime object from an Unix timestamp (the value returned by time() you can use DateTime::createFromFormat()

$current_time = time();
$now = DateTime::createFromFormat('U', $current_time);

Or you can pass the timestamp prefixed with '@' to DateTime::__construct():

$current_time = time();
$now = new DateTime('@'.$current_time);

This format is explained in the Compound date/time formats page.

But the easiest way to create a DateTime object that contains the current date and time is to either pass 'now' as argument to the constructor or omit it altogether:

$now1 = new DateTime('now');
$now2 = new DateTime();

The two DateTime objects constructed above should be identical (there is a small chance they are 1-second apart, though) and they both must contain the current date & time.