2024 年 PHP Conference Japan

IntlDateFormatter 類別

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

簡介

日期格式器是一個具體類別,可以使用模式字串和/或預設模式,進行地區相關的日期格式化/解析。

此類別代表 ICU 日期格式化功能。它允許使用者以當地語系化的格式顯示日期,或使用模式字串和/或預設模式將字串解析為 PHP 日期值。

類別概要

class IntlDateFormatter {
/* 常數 */
public const int FULL;
公開 常數 int LONG;
公開 常數 int MEDIUM;
公開 常數 int SHORT;
公開 常數 int NONE;
公開 常數 int RELATIVE_FULL;
公開 常數 int RELATIVE_LONG;
公開 常數 int RELATIVE_MEDIUM;
公開 常數 int RELATIVE_SHORT;
公開 常數 int GREGORIAN;
公開 常數 int TRADITIONAL;
/* 方法 */
公開 __construct(
    ?字串 $locale,
    int $dateType = IntlDateFormatter::FULL,
    int $timeType = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|字串|null $timezone = null,
    IntlCalendar|int|null $calendar = null,
    ?字串 $pattern = null
)
公開 靜態 create(
    ?字串 $locale,
    int $dateType = IntlDateFormatter::FULL,
    int $timeType = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|字串|null $timezone = null,
    IntlCalendar|int|null $calendar = null,
    ?字串 $pattern = null
): ?IntlDateFormatter
公開 localtime(字串 $string, 整數 &$offset = null): 陣列|false
公開 parse(字串 $string, 整數 &$offset = null): 整數|浮點數|false
公開 setLenient(布林值 $lenient):
公開 setPattern(字串 $pattern): 布林值
}

預定義常數

這些常數用於在 DateType 和 TimeType 的建構子中指定不同的格式。

IntlDateFormatter::NONE 整數 (int)
不包含此元素
IntlDateFormatter::FULL 整數 (int)
完整指定的樣式(例如:星期二, 1952 年 4 月 12 日 或 下午 3:30:42 PST)
IntlDateFormatter::LONG 整數 (int)
長樣式(例如:1952 年 1 月 12 日 或 下午 3:30:32)
IntlDateFormatter::MEDIUM 整數 (int)
中等樣式(例如:1952 年 1 月 12 日)
IntlDateFormatter::SHORT 整數 (int)
最簡略的樣式,僅包含必要資料(例如:52/12/13 或 下午 3:30)
IntlDateFormatter::RELATIVE_FULL 整數 (int)
IntlDateFormatter::FULL 相同,但昨天、今天和明天分別顯示為 yesterdaytodaytomorrow。從 PHP 8.0.0 開始提供,僅適用於 dateType 參數。
IntlDateFormatter::RELATIVE_LONG 整數 (int)
IntlDateFormatter::LONG 相同,但昨天、今天和明天分別顯示為 yesterdaytodaytomorrow。從 PHP 8.0.0 開始提供,僅適用於 dateType 參數。
IntlDateFormatter::RELATIVE_MEDIUM 整數 (int)
IntlDateFormatter::MEDIUM 相同,但昨天、今天和明天分別顯示為 yesterdaytodaytomorrow。從 PHP 8.0.0 開始提供,僅適用於 dateType 參數。
IntlDateFormatter::RELATIVE_SHORT 整數 (int)
IntlDateFormatter::SHORT 相同,但昨天、今天和明天分別顯示為 yesterdaytodaytomorrow。從 PHP 8.0.0 開始提供,僅適用於 dateType 參數。

以下整數常數用於指定曆法。這些曆法都直接基於格里曆。非格里曆需要在語系設定中指定。例如:locale="hi@calendar=BUDDHIST"。

IntlDateFormatter::TRADITIONAL 整數 (int)
非格里曆
IntlDateFormatter::GREGORIAN 整數 (int)
格里曆

更新日誌

版本 說明
8.4.0 類別常數現在已設定類型。

目錄

新增註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top