格式化输出提问时间:
/** * 格式化时间戳 */ function time_format ($time) { $now = time(); $today = strtotime(date('y-m-d')); $zuotian = strtotime('-1 day', $today); $diff = $now - $time; $str = ''; switch (true) { case $diff < 60 : $str = '刚刚'; break; case $diff < 3600 : $str = floor($diff / 60) . '分钟前'; break; case $diff < (3600 * 8) : $str = floor($diff / 3600) . '小时前'; break; case $time > $today : $str = '今天' . date('H:i', $time); break; case $time > $zuotian : $str = '昨天' . date('H:i', $time); break; default : $str = date('Y-m-d H:i', $time); } return $str; }
前台使用:
<span>{$v.time|time_format=###}</span>