我有这个时间戳PHP代码,它没有显示正确的时间.它总是显示8小时前,当时间假设是几分钟前.
/**
* Convert a timestap into timeago format
* @param time
* @return timeago
*/
public static function timeago($time, $tense = "ago"){
if(empty($time)) return "n/a";
$time=strtotime($time);
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] $tense ";
} …Run Code Online (Sandbox Code Playgroud)