All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#中PrintDocumentPrintDocument组件的事件使用实例
PHP5.2+APACHE2.2+BugFree1.0的安装_php资料_编程技术
无刷新仿google波形扭曲彩色Asp.net验证码_[Asp.Net教程]
C#中ref和out的使用小结_[Asp.Net教程]
SQL,Server数据库性能优化_[SQL,Server教程]
PHP利用cookie做的投票程序_[PHP教程]
菜鸟的最爱,.NET经典代码汇总(四)_.net资料_编程技术
Microsoft,OLE,DB,Provider,for,SQL,Server,错误,'80040e37',对象名,’无效。_mssql学习_编程技术
Delphi以XPManifest组件显示界面
实例代码:图片、文件防盗链程序_.net资料_编程技术
Reading number is top 10 pictures
Small s breast enhancement demonstration
The money of more than 100 countries and regions18
Household design comfortable contracted
More attractive than sora aoi2
女人化妆前后的对比
A man's favorite things8
2012 national geographic daily picture9
Sora aoi possession photo1
29 the belle stars after bath figure1
Sell the barbecue as says father du breul1
Download software ranking
Tram sex maniac 2 (H) rar bag4
Boxer vs Yellow1
Boxer's Top ten classic battle6
Unix video tutorial14
JSP+Ajax Web development typical examples
传奇私服架设教程
jdk1.6 for windows
VC++6.0简体中文版
Detective task-the top secret prostitution files
在线棋牌游戏3.05版
归海一刀 published in(发表于) 2014/2/17 7:29:46 Edit(编辑)
PHP多种格式显示日期函数_[PHP教程]

PHP多种格式显示日期函数_[PHP教程]

PHP多种格式显示日期函数_[PHP教程]
显示效果如下:

2010-01-21 10:33:15
35分钟前
--------------------------------
2010-01-20 10:33:15
1天前
--------------------------------
2010-01-19 9:33:15
2天1小时前
--------------------------------
2010-01-14 10:33:15
1星期前
--------------------------------
2010-01-7 08:33:15
2星期前
--------------------------------
2009-12-13 10:33:15
1个月9天前
--------------------------------
2009-01-18 10:33:15
1年前
--------------------------------
2008-11-18 10:33:15
1年2月前
--------------------------------


代码:

function usertime($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*7))
{
$d = $ptime / (3600*24);
$h = ( $ptime % (3600*24)) / 3600;
$m = ceil( ( ( $ptime % (3600*24)) % 3600 ) / 60 );
//$pct = sprintf("%d天%d小时%d分钟前", $d, $h, $m );
if($h>=1) {
$pct = sprintf("%d天%d小时前", $d, $h);
}
else{
$pct = sprintf("%d天前",$d);
}

}

else if( $ptime > (3600 * 24 *7) && $ptime < (3600*24*30))
{
$w = $ptime / (3600*24*7);
$d = ($ptime % (3600*24*7))/(3600*24);
$h=(($ptime%(3600*24*7))%(3600*24))/3600;
$m = ceil( ( ( $ptime % (3600*24)) % 3600 ) / 60 );
//$pct = sprintf("%d星期%d天%d小时前",$w, $d, $h);
if($d>=1) {
$pct = sprintf("%d星期%d天前",$w, $d);
}
else{
$pct = sprintf("%d星期前",$w);
}

}

else if( $ptime > (3600 * 24 *30) && $ptime < (3600*24*365))
{
$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 );
if($d>=1) {
$pct = sprintf("%d个月%d天前",$mt,$d);
}
else{
$pct = sprintf("%d个月前",$mt);
}

}
else //n年前
{
$y = $ptime / (3600*24*365);
$m = ($ptime % (3600*24*30*12))/(3600*24*30);
if($m>=1) {
$pct = sprintf("%d年%d月前",$y,$m);
}
else{
$pct = sprintf("%d年前",$y);
}

}

return $pct;
}

?>


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.