CakeFest 2024: The Official CakePHP Conference

IntlDateFormatter クラス

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

はじめに

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

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

クラス概要

class IntlDateFormatter {
/* 定数 */
public const int FULL;
public const int LONG;
public const int MEDIUM;
public const int SHORT;
public const int NONE;
public const int RELATIVE_FULL;
public const int RELATIVE_LONG;
public const int RELATIVE_MEDIUM;
public const int RELATIVE_SHORT;
public const int GREGORIAN;
public const int TRADITIONAL;
/* メソッド */
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
)
public static create(
    ?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
public static formatObject(IntlCalendar|DateTimeInterface $datetime, array|int|string|null $format = null, ?string $locale = null): string|false
public getErrorCode(): int
public getLocale(int $type = ULOC_ACTUAL_LOCALE): string|false
public isLenient(): bool
public localtime(string $string, int &$offset = null): array|false
public parse(string $string, int &$offset = null): int|float|false
public setCalendar(IntlCalendar|int|null $calendar): bool
public setLenient(bool $lenient): void
public setPattern(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
グレゴリオ暦

目次

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top