我想显示像Twitter和FB时间格式(发表于3小时前,发布2分钟前等等...)显示“很久以前”,而不是在PHP笨日期时间
我已经试图这段代码没有成功:
function format_interval($timestamp, $granularity = 2) {
$units = array('1 year|@count years' => 31536000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
$output = '';
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$floor = floor($timestamp/$value);
$output .= ($output ? ' ' : '') . ($floor == 1 ? $key[0] : str_replace('@count', $floor, $key[1]));
$timestamp %= $value;
$granularity--;
}
if ($granularity == 0) {
break;
}
}
我使用该函数与一个回调到另一个函数等函数:$ this-> format_interval();并将它传递给我的查看
我现在的格式日期:2012-07-26 09:31:PM与已存储在我的数据库
任何帮助将非常感激!
这样做的窍门,感谢您的帮助;) – user990463 2012-07-31 10:36:29
@ user990463:不客气!我很高兴这很有帮助。 – 2012-07-31 13:15:19