我有這個時間戳php代碼,它不顯示正確的時間。它總是顯示8小時前的時間假設是幾分鐘前。將時間戳轉換爲PHP前的時間
/**
* 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 ";
}
我真的不明白爲什麼它不能正常工作
什麼是輸入你期待什麼輸出? – naomik
使用碳依賴,它會使你easyer你 –