- 论坛徽章:
- 0
|
?php
/**
* 函数名:puttime
* 作用:计算参数时间与当前时间差,精确的秒,最大单位天
* 作者:七夜
* 日期:2009-10-12
*/
function puttime( $times )
{
if( $times == '' || $times==0) return false;
$dtime =is_int($times) ? $times : strtotime($times);
$ptime = time() - $dtime;
if( $ptime 60 )
{
$pct = sprintf("发布于%d秒前",$ptime);
}
else if( $ptime > 60 && $ptime 3600 )
{
$pct = sprintf("发布于%d分钟前",ceil( $ptime / 60 ));
}
else if( $ptime > 3600 && $ptime (3600 * 24) )
{
$pct = sprintf("发布于%d小时%d分钟前", floor( $ptime / 3600 ), ceil( ( $ptime % 3600 ) / 60 ));
}
else if( $ptime > (3600 * 24) && $ptime (3600*24*30))
{
$d = $ptime / (3600*24);
$h = ( $ptime % (3600*24)) / 3600;
$m = ceil( ( ( $ptime % (3600*24)) % 3600 ) / 60 );
$pct = sprintf("发布于%d天%d小时%d分钟前", $d, $h, $m );
}
else
{
$mt = $ptime / ( 3600*24*30);
$d = ($ptime % ( 3600*24 * 30))/ (3600*24);
$h = ( ($ptime % ( 3600*24 * 30))% (3600*24)) / 3600;
$m = ceil( ( ($ptime % ( 3600*24 * 30))% (3600*24)) % 3600 / 60 );
$pct = sprintf("发布于%d月%d天%d小时%d分钟前", $mt, $d, $h, $m );
}
return $pct;
}
echo puttime( '2008-9-10 23:59:59' ).'
';
?>
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/94441/showart_2068615.html |
|