PHP代码里处理显示几天前,几小时前,几分钟前
<?php
/**
 * Created by PhpStorm.
 * User: yang
 * Date: 2016/8/26
 * Time: 16:15
 */
function dayfast($the_time)
{
    $now_time = date("Y-m-d H:i:s", time() );
    $now_time = strtotime($now_time);
    $show_time = strtotime($the_time);
    $dur = $now_time - $show_time;
    if ($dur < 0) {
        return $the_time;
    } else {
        if ($dur < 60) {
            return $dur . '秒前';
        } else {
            if ($dur < 3600) {
                return floor($dur / 60) . '分钟前';
            } else {
                if ($dur < 86400) {
                    return floor($dur / 3600) . '小时前';
                } else {
                    if ($dur < 259200) {//3天内
                        return floor($dur / 86400) . '天前';
                    } else {
                        $the_time = date("Y-m-d",strtotime($the_time));
                        return $the_time;
                    }
                }
            }
        }
    }
}
$time1 = str_replace("CST", "", "Fri Aug 26 00:00:00 CST 2016");
$tiem2 = strtotime($time1);
$abc = date("Y-m-d H:i:s", $tiem2);
echo dayfast($abc);
