unix时间戳做比较,精确到秒time()函数返回的时间戳
如果你的时间格式是"2008-10-20 11:11:11"的话,可以用strtotime()来转换.

解决方案 »

  1.   

    貌似简单,实际上有点复杂的问题,哈哈
    看看这个<?php
        $regist1 = "05/12/2006";
        $regist2 = "10/05/2007";    list($month1,$day1,$year1) = explode("/",$regist1);
        list($month2,$day2,$year2) = explode("/",$regist2);    $regist1 = mktime(0,0,0,$month1,$day1,$year1);
        $regist2 = mktime(0,0,0,$month2,$day2,$year2);    $time_difference = $regist2-$regist1;    echo ("时间差:");
        echo date("Y",$time_difference) - 1970;
        echo ("年");
        echo date("m",$time_difference) - 1;
        echo ("个月");
        echo date("d",$time_difference) - 1;
        echo ("天");
    ?>
      

  2.   

    <?php
    /**
     * 时间差计算
     *
     * @param Timestamp $time
     * @return String Time Elapsed
     * @author Shelley Shyan
     * @copyright http://phparch.cn (Professional PHP Architecture)
     */
    function time2Units ($time)
    {
       $year   = floor($time / 60 / 60 / 24 / 365);
       $time  -= $year * 60 * 60 * 24 * 365;
       $month  = floor($time / 60 / 60 / 24 / 30);
       $time  -= $month * 60 * 60 * 24 * 30;
       $week   = floor($time / 60 / 60 / 24 / 7);
       $time  -= $week * 60 * 60 * 24 * 7;
       $day    = floor($time / 60 / 60 / 24);
       $time  -= $day * 60 * 60 * 24;
       $hour   = floor($time / 60 / 60);
       $time  -= $hour * 60 * 60;
       $minute = floor($time / 60);
       $time  -= $minute * 60;
       $second = $time;
       $elapse = '';   $unitArr = array('年'  =>'year', '个月'=>'month',  '周'=>'week', '天'=>'day',
                        '小时'=>'hour', '分钟'=>'minute', '秒'=>'second'
                        );   foreach ( $unitArr as $cn => $u )
       {
           if ( $$u > 0 )
           {
               $elapse = $$u . $cn;
               break;
           }
       }   return $elapse;
    }$past = 2052345678; // Some timestamp in the past
    $now  = time();     // Current timestamp
    $diff = $now - $past;echo '发表于' . time2Units($diff) . '前';
    ?>
      

  3.   

    <?php 
    $date=date('Y-m-d G:i:s');
    print_r($date);
    $date1 = strtotime($date);
    echo "<br>";
    $date_min=date("Y-m-d G:i:s", mktime(date("G"),date("i")-20,date("s")-10,date("m"),date("d"),date("Y")));
    print_r($date_min);
    $date2 = strtotime($date_min);
    echo "<br>";
    $del = round(($date1-$date2)/60);
    print_r($del);
    exit();
    ?>
    还有一个
    按照jakey9826 说的用了strtotime
    这个我测试了
    如果只是计算出分钟,那没有问题