根据刚刚,1分钟前,1小时前,几天前显示文章发布日期
2013-12-18 06:39
441 查看
一分钟之内发布的,显示“刚刚”
一小时之内发布的,显示“XX分钟前”一个月之内发布的,显示“XX天前”
一个月外的直接显示日期。
代码收藏:
//发表于几分钟前 function kele_time_since($older_date, $newer_date = false) { $chunks = array( array(60 * 60 * 24 * 365 , '年'), array(60 * 60 * 24 * 30 , '月'), //array(60 * 60 * 24 * 7, '周'), array(60 * 60 * 24 , '天'), array(60 * 60 , '小时'), array(60 , '分钟'), ); // www.jbxue.com $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date; $since = $newer_date - abs(strtotime($older_date)); //根据自己的需要调整时间段,下面的24则表示小时,根据需要调整吧 $chunks_count=count($chunks); if($since < 60 * 60 * 24*30){ for ($i = 0, $j = $chunks_count; $i < $j; $i++){ $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; if (($count = floor($since / $seconds)) != 0){ break; } } $out = ($count == 1) ? '1'.$name : "$count{$name}"; if(0==$count){ return "刚刚"; } return $out."前"; }else{ the_time(get_option('date_format')); } }
相关文章推荐
- 根据刚刚,1分钟前,1小时前,几天前显示文章发布日期
- 利用dedecms给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片
- PHP 显示文章发布日期 一小时前 一天前 一月前 一年前
- 织梦DEDECMS中让近三天发布的文章显示红色日期或加上new字或小图片的方法
- 给近三天(或当天)发布的文章显示红色日期或加上new字或new小图-织梦CMS
- 给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片等
- 利用dedecms给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片
- 如何用DataGrid实现根据日期判断是否显示New标志
- 织梦dedecms后台发布文章提示“标题不能为空”,编辑器内容无法显示中文
- js 类似发微博或者微信朋友圈的时间显示 刚刚 几天前
- 数据中显示"刚刚、几天前、几天前、几个月"等个人的想法
- js根据指定日期以周显示时间区间
- 再次给力发布,首款全中文习惯,支持鼠标滑动多选的多月(可以显示N个月)的日历控件,界面仿Twitter风格,多语言支持,Ctrl/Shift多选支持,日期范围限制支持,自定义事件支持
- 根据日期显示星期几
- android 根据系统日期格式显示日期
- 如何用DataGrid实现根据日期判断是否显示New标志
- 根据日期显示星期几
- DedeCms最新文章显示红色日期或加上new字或new小图片
- 发布文章不显示在旧版
- phpcms文章发布时首页不显示及文章内页图片显示