IntlDateFormatter::formatObject

datefmt_format_object

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL intl >= 3.0.0)

IntlDateFormatter::formatObject -- datefmt_format_objectオブジェクトの書式を設定する

説明

オブジェクト指向型

publicstaticIntlDateFormatter::formatObject(IntlCalendar|DateTimeInterface$datetime, array|int|string|null$format = null, ?string$locale = null): string|false

手続き型

datefmt_format_object(IntlCalendar|DateTimeInterface$datetime, array|int|string|null$format = null, ?string$locale = null): string|false

この関数は、IntlCalendar オブジェクトや DateTime オブジェクトをフォーマットします。その際、明示的に IntlDateFormatter オブジェクトを作る必要はありません。

一時的な IntlDateFormatter が作られ、 渡されたオブジェクトのタイムゾーンを受け取ります。PHP に組み込まれているタイムゾーンデータベースは使いません。 そのかわりに、ICU のタイムゾーンデータベースを使います。 したがって、DateTime オブジェクトで使うタイムゾーン ID は ICU のデータベースに存在するものでなければいけません。

パラメータ

datetime

IntlCalendar あるいは DateTime 型のオブジェクト。 このオブジェクトの中のタイムゾーン情報を使います。

format

日付/時刻のフォーマット方法。二つの要素からなる配列 (最初の要素が日付のスタイル、二番目の要素が時刻のスタイル。それぞれ、定数 IntlDateFormatter::NONEIntlDateFormatter::SHORTIntlDateFormatter::MEDIUMIntlDateFormatter::LONGIntlDateFormatter::FULL のいずれか)、 これらの定数のいずれかの値を表す int 型 (日付と時刻の両方に使います)、あるいは » ICU のドキュメント にあるフォーマットを表す文字列を指定します。null を渡した場合はデフォルトのスタイルを使います。

locale

利用するロケール。null を渡した場合は デフォルトのロケール を使います。

戻り値

結果を文字列で返します。失敗した場合に false を返します。

例1 IntlDateFormatter::formatObject() の例

<?php

ini_set('date.timezone', 'UTC');

ini_set('intl.default_locale', 'fr_FR');

$cal = IntlCalendar::fromDateTime("2013-06-06 17:05:06 Europe/Dublin");
echo
"default:\n\t",
IntlDateFormatter::formatObject($cal),
"\n";

echo
"long \$format (full):\n\t",
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL),
"\n";

echo
"array \$format (none, full):\n\t",
IntlDateFormatter::formatObject($cal, array(
IntlDateFormatter::NONE,
IntlDateFormatter::FULL)),
"\n";

echo
"string \$format (d 'of' MMMM y):\n\t",
IntlDateFormatter::formatObject($cal, "d 'of' MMMM y", 'en_US'),
"\n";

echo
"with DateTime:\n\t",
IntlDateFormatter::formatObject(
new
DateTime("2013-09-09 09:09:09 Europe/Madrid"),
IntlDateFormatter::FULL,
'es_ES'),
"\n";

上の例の出力は以下となります。

default: 6 juin 2013 17:05:06 long $format (full): jeudi 6 juin 2013 17:05:06 heure d’été irlandaise array $format (none, full): 17:05:06 heure d’été irlandaise string $format (d 'of' MMMM y): 6 of June 2013 with DateTime: lunes, 9 de septiembre de 2013 09:09:09 Hora de verano de Europa central
To Top