在 Elgg 中更改友好的时间格式
Change friendly time format in Elgg
我用的是elgg 2.6.3.
我想将所有事件的日期时间格式从持续时间(从创建日期到现在)更改为创建日期。
例如我想将 "posted 1780 Days ago" 更改为 "posted on Dec 20, 2011".
我该如何更改此代码以解决此问题? (此代码return日期时间格式)
function elgg_get_friendly_time($time, $current_time = null) {
if (!$current_time) {
$current_time = time();
}
// return a time string to short circuit normal time formatting
$params = array('time' => $time, 'current_time' => $current_time);
$result = elgg_trigger_plugin_hook('format', 'friendly:time', $params, null);
if ($result) {
return $result;
}
$diff = abs((int)$current_time - (int)$time);
$minute = 60;
$hour = $minute * 60;
$day = $hour * 24;
if ($diff < $minute) {
return elgg_echo("friendlytime:justnow");
}
if ($diff < $hour) {
$granularity = ':minutes';
$diff = round($diff / $minute);
} else if ($diff < $day) {
$granularity = ':hours';
$diff = round($diff / $hour);
} else {
$granularity = ':days';
$diff = round($diff / $day);
}
if ($diff == 0) {
$diff = 1;
}
$future = ((int)$current_time - (int)$time < 0) ? ':future' : '';
$singular = ($diff == 1) ? ':singular' : '';
return elgg_echo("friendlytime{$future}{$granularity}{$singular}", array($diff));
}
我问我的问题。
只需如下更改此功能(非常简单易行):
function elgg_get_friendly_time($time)
{
return elgg_echo(date("Y-m-d H:i:s", $time));
}
我用的是elgg 2.6.3.
我想将所有事件的日期时间格式从持续时间(从创建日期到现在)更改为创建日期。
例如我想将 "posted 1780 Days ago" 更改为 "posted on Dec 20, 2011".
我该如何更改此代码以解决此问题? (此代码return日期时间格式)
function elgg_get_friendly_time($time, $current_time = null) {
if (!$current_time) {
$current_time = time();
}
// return a time string to short circuit normal time formatting
$params = array('time' => $time, 'current_time' => $current_time);
$result = elgg_trigger_plugin_hook('format', 'friendly:time', $params, null);
if ($result) {
return $result;
}
$diff = abs((int)$current_time - (int)$time);
$minute = 60;
$hour = $minute * 60;
$day = $hour * 24;
if ($diff < $minute) {
return elgg_echo("friendlytime:justnow");
}
if ($diff < $hour) {
$granularity = ':minutes';
$diff = round($diff / $minute);
} else if ($diff < $day) {
$granularity = ':hours';
$diff = round($diff / $hour);
} else {
$granularity = ':days';
$diff = round($diff / $day);
}
if ($diff == 0) {
$diff = 1;
}
$future = ((int)$current_time - (int)$time < 0) ? ':future' : '';
$singular = ($diff == 1) ? ':singular' : '';
return elgg_echo("friendlytime{$future}{$granularity}{$singular}", array($diff));
}
我问我的问题。
只需如下更改此功能(非常简单易行):
function elgg_get_friendly_time($time)
{
return elgg_echo(date("Y-m-d H:i:s", $time));
}