當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateTime::localeTime方法代碼示例

本文整理匯總了PHP中DateTime::localeTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTime::localeTime方法的具體用法?PHP DateTime::localeTime怎麽用?PHP DateTime::localeTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DateTime的用法示例。


在下文中一共展示了DateTime::localeTime方法的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();
             }
         }
     }
 }
開發者ID:reedmaniac,項目名稱:reedmaniac,代碼行數:30,代碼來源:DateTimeHelper.php


注:本文中的DateTime::localeTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。