<?php
public function actionIndex(){
$time = xxx; //发布文章的时间
return $this->format_date($time);
}
//获取发布文章后过了多长时间
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.'前';
}
}
}
?>