如何正确实现PHP显示文章发布时间
大家都知道,
PHP显示文章发布时间代码示例:
- < ?php
- function format_date($dateStr) {
- $limit = time() - strtotime($dateStr);
- $r = "";
- if($limit < 60) {
- $r = 刚刚;
- } elseif($limit >= 60 && $limit
< 3600) { - $r = floor($limit / 60) . 分钟前;
- } elseif($limit >= 3600 && $limit
< 86400) { - $r = floor($limit / 3600) . 小时前;
- } elseif($limit >= 86400 && $limit
< 2592000) { - $r = floor($limit / 86400) . 天前;
- } elseif($limit >= 2592000 && $limit
< 31104000) { - $r = floor($limit / 2592000) . 个月前;
- } else {
- $r = "很久前";
- }
- return $r . "(" . $dateStr . ")";
- }
- echo "发表于:" . format_date
("2009-11-25 23:40"); - ?>
以上这段代码就是PHP显示文章发布时间的具体实现方法介绍。
本文地址:http://www.phprm.com/frame/php1003979.html
转载随意,但请附上文章地址:-)