时间变成多少分钟前

function get_long_time($date){
    $curr = time();
    $date = strtotime($date);
    $tmp = $curr - $date;
    if($tmp < 60){
        $re = $tmp.'秒前';
    }else if($tmp < 3600){
        $re = floor($tmp/60).'分钟前';
    }else if($tmp < 86400){
        $re = floor($tmp/3600).'小时前';
    }else if($tmp < 259200){//3天内
        $re = floor($tmp/86400).'天前';
    }else{
        $re = date('m月d日',$date);
    }
    echo $re;
}
function tranTime($time) {
    $rtime = date("m-d H:i", $time);
    $htime = date("H:i", $time);
    $time = time() - $time;
 
    if ($time < 60) {
        $str = '刚刚';
    } elseif ($time < 60 * 60) {
        $min = floor($time / 60);
        $str = $min.'分钟前';
    } elseif ($time < 60 * 60 * 24) {
        $h = floor($time / (60 * 60));
        $str = $h.'小时前 '.$htime;
    } elseif ($time < 60 * 60 * 24 * 3) {
        $d = floor($time / (60 * 60 * 24));
        $str = ($d == 1) ? '昨天 '.$rtime : '前天 '.$rtime;
    } else {
        $str = $rtime;
    }
 
    return $str;
}

  

posted @ 2015-07-30 09:44  Adtuu  阅读(257)  评论(0编辑  收藏  举报