博客的发布时间用到了下面的函数,将博文发布的时间按几天前、几分钟前、几秒前的方式进行转换,以下是函数的示例:
- function time_show($time){
- $time_start=$time;
- if ($time==''){
- $time_result='--';
- }else{
- $time=time()-strtotime($time);
- if ($time<=60){ //1分钟以内
- $time_result=$time." 秒前";
- }elseif($time<=60*60){ //1小时以内
- $time_result=floor($time/60)." 分钟前"; //ceil向上取整,floor小数部分舍去取整
- }elseif($time<=(60*60*24*1)){ //1天以内
- $time_result=floor($time/3600)." 小时前";
- }elseif($time<=(60*60*24*4)){ //4天以内
- $time_result=floor($time/3600/24)." 天前";
- }else{
- $time_result=date("Y-m-d H:i",strtotime($time_start));
- }
- }
- return $time_result;
- }
- //调用方法
- echo time_show("2015-11-22 12:00:00");
以上就是PHP将显示的日期转变为几天、几分钟、几秒前的显示方法的详细内容,更多关于PHP将显示的日期转变为几天、几分钟、几秒前的显示方法的资料请关注九品源码其它相关文章!