查詢

IntlDateFormatter::getLocale()函式—用法及示例

「 返回當前 IntlDateFormatter 物件的區域設定 」


函式名: IntlDateFormatter::getLocale()

適用版本: PHP 5 >= 5.3.0, PHP 7, PHP 8

用法: IntlDateFormatter::getLocale() 函式返回當前 IntlDateFormatter 物件的區域設定。

示例:

// 建立一個 IntlDateFormatter 物件
$dateFormatter = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/New_York',
    IntlDateFormatter::GREGORIAN
);

// 獲取當前物件的區域設定
$locale = $dateFormatter->getLocale();

// 列印輸出區域設定
echo "當前區域設定是:" . $locale;

輸出:

當前區域設定是:en_US

在上面的示例中,我們首先建立了一個 IntlDateFormatter 物件,然後使用 getLocale() 函式獲取了當前物件的區域設定。最後,我們列印輸出了區域設定,得到了 "en_US"。這表示當前物件的日期格式將使用英語(美國)的語言和地區設定進行格式化。

補充糾錯
熱門PHP函式
分享連結