基本上,我要做的是将mysql时间戳转换为"xx秒前“格式。我使用这个函数- $age = time() - strtotime($eventTime)。我得到了结果,但它以秒为单位显示一个小时后的时间(-3600s)。例如,如果我现在发帖,它会显示(-3600s前)。这会是什么问题呢?
发布于 2013-07-18 11:44:57
假设您的MySQL会话和您的PHP设置都共享同一时区,您可以使用类似下面的内容来获取一个合适的英语时间段:
function toFriendlyTime($seconds) {
// Used in the item view, this function returns a 'friendly', rough-idea type time, like "3 hours" or "4 months"
$measures = array(
'month'=>30*24*60*60,
'week'=>7*24*60*60,
'day'=>24*60*60,
'hour'=>60*60,
'minute'=>60,
'second'=>1,
);
foreach ($measures as $label=>$amount) {
if ($seconds >= $amount) {
$howMany = floor($seconds / $amount);
return $howMany." ".$label.($howMany > 1 ? "s" : "");
}
}
return "1 second";
}https://stackoverflow.com/questions/17713759
复制相似问题