(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)
IntlCalendar::createInstance — 建立新的 IntlCalendar
物件導向風格
$timezone
= null
, ?字串 $locale
= null
): ?IntlCalendar程序式風格
$timezone
= null
, ?字串 $locale
= null
): ?IntlCalendar給定時區和地區設定,此方法會建立一個 IntlCalendar 物件。這個工廠方法可能會返回 IntlCalendar 的子類別。
建立的日曆將根據系統時間表示其建立時的時間實例。可以透過呼叫無參數的 IntCalendar::clear() 來清除所有欄位。另請參閱 IntlGregorianCalendar::__construct()。
timezone (時區)
要使用的時區。
null
,在這種情況下,將使用預設時區,如 ini 設定 date.timezone 中指定,或透過函式 date_default_timezone_set() 設定,以及由 date_default_timezone_get() 返回。
一個 IntlTimeZone 物件,將直接使用。
一個 DateTimeZone 物件。將提取其識別碼並建立一個 ICU 時區物件;時區將由 ICU 的資料庫支援,而不是 PHP 的。
一個 字串,它應該是一個有效的 ICU 時區識別碼。請參閱 IntlTimeZone::createTimeZoneIDEnumeration()。也接受原始偏移量,例如 "GMT+08:30"
。
locale (地區設定)
建立的 IntlCalendar 實例,或失敗時返回 null
。
範例 #1 IntlCalendar::createInstance()
<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'Europe/Madrid');
$cal = IntlCalendar::createInstance();
echo "No arguments\n";
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";
echo "Explicit timezone\n";
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT());
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";
echo "Explicit locale (with calendar)\n";
$cal = IntlCalendar::createInstance(NULL, 'es_ES@calendar=persian');
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
上述範例會輸出
No arguments string(21) "IntlGregorianCalendar" string(68) "martes 18 de junio de 2013 14:11:02 Hora de verano de Europa Central" Explicit timezone string(21) "IntlGregorianCalendar" string(45) "martes 18 de junio de 2013 12:11:02 GMT+00:00" Explicit locale (with calendar) string(12) "IntlCalendar" string(70) "martes 28 de Khordad de 1392 14:11:02 Hora de verano de Europa Central"