比较PHP中的unix时间戳[关闭]

In PHP I have:

$diff = abs(strtotime(date('m/d/Y h:i:s')) - strtotime($latest));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
echo floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

How do I get the difference in seconds? I've tried the following:

$diff = abs(strtotime(date('m/d/Y h:i:s')) - strtotime($latest));

Use DateTime instead, it will make your code much cleaner.

$latest = new DateTime($latest);
$now = new DateTime();

$diff = $latest->diff($now);
echo $diff->format('%y years %m months %d days');

A timestamp is just a number of seconds from 01/01/1970. So its as simple as:

<?php
    $now = time();
    $latest = "21-11-2012 14:44";
    $latest = strtotime($latest);
    $diff = ($now - $latest);
    //$diff = Number of seconds difference between now and 21-11-2012 14:44
?>

Also take a look at the DateTime class which has a lot more functionality when dealing with dates.