php model里时间处理

    /**
     * 距离时间
     * @author kangjy
     * @return string
     */
    public function getAgoTime()
    {
        if(!$this->created_at)
            return '';
            $curtime=$this->created_at;
             
            //明天凌晨的时间戳
            $yesterday= strtotime(date('Y-m-d',strtotime('-1 day')));
            //今天凌晨的时间戳
            $today= strtotime(date('Y-m-d',time()));
            //日期标题
            $timename='';
            if($curtime-$today>=0){
                $num=($curtime-$today)/(60*60);
                $timename=intval($num).'小时前';
            }
            if($curtime-$yesterday>=2*24*60*60){
                $num=($curtime-$today)/(24*60*60);
                $timename=intval($num).'天前';
            }
            if(($curtime-$yesterday)<0&&(date('Y',time())==date('Y',$curtime)))
                $timename=date('m月d日',$curtime);
                if(($curtime-$yesterday)<0&&(date('Y',time())!=date('Y',$curtime)))
                    $timename=date('Y年m月d日',$curtime);
                    return $timename;
    }
    
    /**
     * 时间轴
     * @author kangjy
     * @return string
     */
    public function getTimeAxis()
    {
        //今天
        if($this->created_at>=strtotime('today')) $timename='今天';
        //昨天
        elseif($this->created_at>=strtotime('yesterday')) $timename='昨天';
        //某月某日
        elseif($this->created_at>=strtotime('1/1')) $timename = date('m月d日',$this->created_at);
        //某年某月某日
        else $timename = date('Y年m月d日',$this->created_at);
        //返回时间轴
        return $timename ;
    }