/* 计算发布时间据当前时间 如1秒前 1分钟前 1小时 1天 1个星期 1个人月 1年 */ function format_dates($time) { if($time <= 0) return '刚刚'; $nowtime = time(); if ($nowtime <= $time) { return "刚刚"; } $t = $nowtime - $time; $f = array( '31536000' => '年', '2592000' => '个月', '604800' => '星期', '86400' => '天', '3600' => '小时', '60' => '分钟', '1' => '秒' ); foreach ($f as $k => $v) { $c = floor($t/$k); if ($c > 0) { return $c . $v . '前'; } } }