php计算几分钟前、几小时前等

function format_date($time){
    $t=time()-$time;
    $f=array(
        '31536000'=>'',
        '2592000'=>'个月',
        '604800'=>'星期',
        '86400'=>'',
        '3600'=>'小时',
        '60'=>'分钟',
        '1'=>''
    );
    foreach ($f as $k=>$v)    {
        if (0 !=$c=floor($t/(int)$k)) {
            return $c.$v.'';
        }
    }
}

// 模拟时间调用

$t = strtotime('2015-9-13 10:15:00');

echo format_date($t);

原文地址:https://www.cnblogs.com/qhorse/p/4785585.html