function nv_publtime_text($timestamp, $full = false)
{
$now = new DateTime;
$ago = new DateTime('@' . $timestamp);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = [
'y' => 'năm',
'm' => 'tháng',
'w' => 'tuần',
'd' => 'ngày',
'h' => 'giờ',
'i' => 'phút',
's' => 'giây'
];
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v;
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' trước' : 'Vừa xong';
}
$row['publtime'] = nv_publtime_text($row['publtime']);
Tác giả: BCB SOLUTIONS
Ý kiến bạn đọc
Những tin mới hơn
Những tin cũ hơn