美文网首页
仿微博显示发布日期

仿微博显示发布日期

作者: jadn | 来源:发表于2016-09-06 11:23 被阅读19次

<?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");

?>

相关文章

网友评论

      本文标题:仿微博显示发布日期

      本文链接:https://www.haomeiwen.com/subject/ncsdettx.html