本文整理汇总了PHP中Localization::dateByLocalization方法的典型用法代码示例。如果您正苦于以下问题:PHP Localization::dateByLocalization方法的具体用法?PHP Localization::dateByLocalization怎么用?PHP Localization::dateByLocalization使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Localization
的用法示例。
在下文中一共展示了Localization::dateByLocalization方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: friendly_date
function friendly_date(DateTimeValue $date, $timezone = null)
{
if ($timezone == null) {
$timezone = logged_user()->getTimezone();
}
//TODO: 7 days before: "Dom at 13:43", older: "Oct, 06 at 15:20"
if ($date->isToday()) {
$now = DateTimeValueLib::now();
$diff = DateTimeValueLib::get_time_difference($date->getTimestamp(), $now->getTimestamp());
if ($diff['hours'] == 0) {
if ($diff['minutes'] >= 0) {
return lang('minutes ago', $diff['minutes']);
} else {
return format_descriptive_date($date);
}
} else {
if ($diff['hours'] > 0) {
return lang('about hours ago', round($diff['hours'] + ($diff['minutes'] > 30 ? 1 : 0)));
} else {
return format_descriptive_date($date);
}
}
} else {
if ($date->isYesterday()) {
return lang('yesterday at', format_time($date));
} else {
$now = DateTimeValueLib::now();
$diff = DateTimeValueLib::get_time_difference($date->getTimestamp(), $now->getTimestamp());
if ($diff['days'] < 7) {
return lang('day at', Localization::dateByLocalization("D", $date->getTimestamp()), format_time($date));
} else {
if ($now->getYear() != $date->getYear()) {
return lang('day at', Localization::dateByLocalization("M d, Y", $date->getTimestamp()), format_time($date));
} else {
return lang('day at', Localization::dateByLocalization("M, d", $date->getTimestamp()), format_time($date));
}
}
}
}
}