php计算相隔几分钟几秒前等

//$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.'前';
}
}
}

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

关闭菜单