查詢

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

「 獲取與IntlDateFormatter物件關聯的時區識別符號 」


函式名稱:IntlDateFormatter::getTimeZoneId()

函式描述:該函式用於獲取與IntlDateFormatter物件關聯的時區識別符號。

函式引數:無

返回值:返回一個字串,表示與IntlDateFormatter物件關聯的時區識別符號。

適用版本:該函式適用於PHP版本5.5及以上,並且需要安裝Intl擴充套件。

示例:

// 建立一個IntlDateFormatter物件
$formatter = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::FULL);

// 獲取與物件關聯的時區識別符號
$timeZoneId = $formatter->getTimeZoneId();

// 輸出時區識別符號
echo "時區識別符號: " . $timeZoneId;

在上面的示例中,我們首先建立了一個IntlDateFormatter物件,該物件與"en_US"地區和FULL樣式關聯。然後,我們使用getTimeZoneId()函式獲取與該物件關聯的時區識別符號,並將其儲存在$timeZoneId變數中。最後,我們將時區識別符號輸出到螢幕上。

請注意,此示例假設您已經正確安裝了Intl擴充套件。如果未安裝該擴充套件,您將無法使用IntlDateFormatter類及其相關函式。

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