本文整理汇总了PHP中DateTime::localeDate方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::localeDate方法的具体用法?PHP DateTime::localeDate怎么用?PHP DateTime::localeDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::localeDate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uiTimestamp
/**
* Returns a UI-facing timestamp for a given {@link DateTime} object.
*
* - If the date/time is from today, only the time will be retuned in a localized format (e.g. “10:00 AM”).
* - If the date/time is from yesterday, “Yesterday” will be returned.
* - If the date/time is from the last 7 days, the name of the day will be returned (e.g. “Monday”).
* - Otherwise, the date will be returned in a localized format (e.g. “12/2/2014”).
*
* @param DateTime $dateTime The DateTime object to be formatted.
*
* @return string The timestamp.
*/
public static function uiTimestamp(DateTime $dateTime)
{
// If it's today, just return the local time.
if (static::isToday($dateTime->getTimestamp())) {
return $dateTime->localeTime();
} else {
if (static::wasYesterday($dateTime->getTimestamp())) {
return Craft::t('Yesterday');
} else {
if (static::wasWithinLast('7 days', $dateTime->getTimestamp())) {
return Craft::t($dateTime->format('l'));
} else {
// Otherwise, just return the local date.
return $dateTime->localeDate();
}
}
}
}