本文整理匯總了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();
}
}
}
}