IntlDateFormatter クラス

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

はじめに

Date Formatter は、パターン文字列や出来合いのパターンを使用して ロケールに依存する日付のフォーマット/パースを行う具象クラスです。

このクラスは ICU の日付フォーマット機能を表します。 これを使用すると、パターン文字列や出来合いのパターンを使用して 日付を各地域のフォーマットで表示したり、 文字列をパースして PHP の日付として扱ったりすることができます。

クラス概要

classIntlDateFormatter {
publicconstintFULL;
publicconstintLONG;
publicconstintMEDIUM;
publicconstintSHORT;
publicconstintNONE;
publicconstintRELATIVE_FULL;
publicconstintRELATIVE_LONG;
publicconstintRELATIVE_MEDIUM;
publicconstintRELATIVE_SHORT;
publicconstintGREGORIAN;
publicconstintTRADITIONAL;
public__construct(
    ?string$locale,
    int$dateType = IntlDateFormatter::FULL,
    int$timeType = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|string|null$timezone = null,
    IntlCalendar|int|null$calendar = null,
    ?string$pattern = null
)
publicstaticcreate(
    ?string$locale,
    int$dateType = IntlDateFormatter::FULL,
    int$timeType = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|string|null$timezone = null,
    IntlCalendar|int|null$calendar = null,
    ?string$pattern = null
): ?IntlDateFormatter
publicgetErrorCode(): int
publicgetLocale(int$type = ULOC_ACTUAL_LOCALE): string|false
publicisLenient(): bool
publiclocaltime(string$string, int&$offset = null): array|false
publicparse(string$string, int&$offset = null): int|float|false
publicsetLenient(bool$lenient): void
publicsetPattern(string$pattern): bool
}

定義済み定数

これらの定数は、DateType や TimeType のコンストラクタでさまざまなフォーマットを指定するために使用します。

IntlDateFormatter::NONE
この要素を含まない
IntlDateFormatter::FULL
完全に指定した形式 (Tuesday, April 12, 1952 AD あるいは 3:30:42pm PST)
IntlDateFormatter::LONG
長い形式 (January 12, 1952 あるいは 3:30:32pm)
IntlDateFormatter::MEDIUM
中間の形式 (Jan 12, 1952)
IntlDateFormatter::SHORT
不可欠なデータのみを扱う最も省略した形式 (12/13/52 あるいは 3:30pm)
IntlDateFormatter::RELATIVE_FULL
IntlDateFormatter::FULL と同じですが、 昨日、今日、明日についてはそれぞれ、 yesterday, today, tomorrow になります。 PHP 8.0.0 以降で、dateType に限って利用可能です。
IntlDateFormatter::RELATIVE_LONG
IntlDateFormatter::LONG と同じですが、 昨日、今日、明日についてはそれぞれ、 yesterday, today, tomorrow になります。 PHP 8.0.0 以降で、dateType に限って利用可能です。
IntlDateFormatter::RELATIVE_MEDIUM
IntlDateFormatter::MEDIUM と同じですが、 昨日、今日、明日についてはそれぞれ、 yesterday, today, tomorrow になります。 PHP 8.0.0 以降で、dateType に限って利用可能です。
IntlDateFormatter::RELATIVE_SHORT
IntlDateFormatter::SHORT と同じですが、 昨日、今日、明日についてはそれぞれ、 yesterday, today, tomorrow になります。 PHP 8.0.0 以降で、dateType に限って利用可能です。

次の整数定数は、暦の種類を指定するものです。 これらの暦は、すべてグレゴリオ暦にもとづくものです。 グレゴリオ暦以外の暦はロケールで指定しなければなりません。 たとえば、 locale="hi@calendar=BUDDHIST" のようになります。

IntlDateFormatter::TRADITIONAL
非グレゴリオ暦
IntlDateFormatter::GREGORIAN
グレゴリオ暦

目次

To Top