Bạn nào có code hay hơn đường chém em nhé. Em cũng góp phong trào cho diễn đàn thôi.
Phần funtion
function nv_time_format( $time ) { global $lang_module; $output = ''; $at_time = NV_CURRENTTIME - $time; if( $at_time > 31536000 ) //nam truoc { $output = floor( $at_time/31536000 ) . " " . $lang_module['yearago']; } elseif( $at_time > 2592000 ) //thang truoc { $output = floor( $at_time/2592000 ) . " " . $lang_module['monthsago']; } elseif( $at_time > 86400 ) { $output = floor( $at_time/86400 ) . " " . $lang_module['daysago']; } elseif( $at_time > 3600 ) { $output = floor( $at_time/3600 ) . " " . $lang_module['housago']; } elseif( $at_time > 60 ) { $output = floor( $at_time/60 ) . " " . $lang_module['minago']; } elseif( $at_time > 0 ) { $output = $lang_module['attime']; } return $output; }
Thêm ngôn ngữ:
$lang_module['yearago'] = 'năm trước'; $lang_module['monthsago'] = 'tháng trước'; $lang_module['daysago'] = 'ngày trước'; $lang_module['housago'] = 'giờ trước'; $lang_module['minago'] = 'phút trước'; $lang_module['attime'] = 'Vừa xong';
Sử dụng:
$time = nv_time_format( $thoigiandangbai ); //1470675600 echo( $time ); //1 ngay truoc
Để tránh trường hợp lỗi font, các bạn lười gõ lại, mình gửi kèm theo file php bên dưới