Internationalization IntlDateFormatter::formatObject
IntlDateFormatter::formatObject
datefmt_format_object
(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL intl >= 3.0.0)
IntlDateFormatter::formatObject -- datefmt_format_object — 개체 서식 지정
설명
객체 지향 스타일
public static IntlDateFormatter::formatObject(IntlCalendar|DateTime $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
이 함수를 사용하면 먼저 IntlDateFormatter 개체를 명시적으로 만들지 않고도 IntlCalendar 또는 DateTime 개체의 서식을 지정할 수 있습니다.
생성될 임시 IntlDateFormatter는 전달된 개체의 시간대를 사용합니다. PHP와 함께 제공되는 시간대 데이터베이스는 사용되지 않으며 대신 ICU가 사용됩니다. 따라서 DateTime 개체에 사용되는 시간대 식별자는 ICU의 데이터베이스에도 있어야 합니다.
매개변수
datetime
- IntlCalendar 또는 DateTime 유형의 개체입니다. 개체의 시간대 정보가 사용됩니다.
format
- 날짜/시간 형식을 지정하는 방법. 이것은 두 개의 요소가 있는 배열일 수 있습니다(첫 번째는 날짜 스타일, 그 다음은 시간 스타일이며 상수
IntlDateFormatter::NONE
,IntlDateFormatter::SHORT
,IntlDateFormatter::MEDIUM
,IntlDateFormatter::LONG
,IntlDateFormatter::FULL
). ), 이러한 상수 중 하나의 값이 있는 int(이 경우 시간과 날짜에 모두 사용됨) 또는 » ICU 문서에 설명된 형식의 문자열입니다.null
이면 기본 스타일이 사용됩니다. locale
- 사용할 로케일 또는 기본 로케일을 사용하려면
null
입니다.
반환 값
결과가 있는 문자열 또는 실패 시 false
입니다.
Examples
예제 #1 IntlDateFormatter::formatObject() 예제
<?php
/* default timezone is irrelevant; timezone taken from the object */
ini_set('date.timezone', 'UTC');
/* default locale is taken from this ini setting */
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