PHP Conference Japan 2024

IntlDateFormatter::getLocale

datefmt_get_locale

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

IntlDateFormatter::getLocale -- datefmt_get_locale取得格式器使用的語系

說明

物件導向風格

public IntlDateFormatter::getLocale(int $type = ULOC_ACTUAL_LOCALE): string|false

程序式風格

datefmt_get_locale(IntlDateFormatter $formatter, int $type = ULOC_ACTUAL_LOCALE): string|false

取得格式器使用的語系。

參數

formatter

格式器資源

type

您可以選擇有效語系或實際語系(分別為 Locale::VALID_LOCALELocale::ACTUAL_LOCALE)。預設值為實際語系。

回傳值

此格式器的語系,若失敗則傳回 false

範例

範例 #1 datefmt_get_locale() 範例

<?php
$fmt
= datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'格式器的語系為:' . datefmt_get_locale($fmt);
echo
'第一個格式化輸出為 ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'格式器的語系為:' . datefmt_get_locale($fmt);
echo
'第二個格式化輸出為 ' . datefmt_format($fmt, 0);

?>

範例 #2 物件導向範例

<?php
$fmt
= new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'locale of the formatter is : ' . $fmt->getLocale();
echo
'First Formatted output is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'locale of the formatter is : ' . $fmt->getLocale();
echo
'Second Formatted output is ' . $fmt->format(0);

?>

以上範例會輸出

locale of the formatter is : en
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
locale of the formatter is : de
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00

另請參閱

新增註解

使用者提供的註解

此頁面沒有使用者提供的註解。
To Top