php实现多少秒前,多少分钟前,多少小时前 人性化时间功能函数
作者:Alpha时间:2017-09-14 阅读数:3037 +人阅读
现在很多网站将时间的显示都变得比较人性化,例如:某某6秒之前发表,某某在1分钟之前执行过 XX 动作等等。最近在做相关的东西于是乎也顺便自己写了一个,较为简单,仅供参考。
<?php> /* *function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前 *timeInt:unix time时间戳 *format:时间显示格式 */ function timeFormat($timeInt,$format='Y-m-d H:i:s'){ if(empty($timeInt)||!is_numeric($timeInt)||!$timeInt){ return ''; } $d=time()-$timeInt; if($d<0){ return ''; }else{ if($d<60){ return $d.'秒前'; }else{ if($d<3600){ return floor($d/60).'分钟前'; }else{ if($d<86400){ return floor($d/3600).'小时前'; }else{ if($d<259200){//3天内 return floor($d/86400).'天前'; }else{ return date($format,$timeInt); } } } } } } </php>
本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com
上一篇:没有了