2024 年日本 PHP 研討會

IntlCalendar::createInstance

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::createInstance建立新的 IntlCalendar

說明

物件導向風格

public static IntlCalendar::createInstance(IntlTimeZone|DateTimeZone|字串|null $timezone = null, ?字串 $locale = null): ?IntlCalendar

程序式風格

intlcal_create_instance(IntlTimeZone|DateTimeZone|字串|null $timezone = null, ?字串 $locale = null): ?IntlCalendar

給定時區和地區設定,此方法會建立一個 IntlCalendar 物件。這個工廠方法可能會返回 IntlCalendar 的子類別。

建立的日曆將根據系統時間表示其建立時的時間實例。可以透過呼叫無參數的 IntCalendar::clear() 來清除所有欄位。另請參閱 IntlGregorianCalendar::__construct()

參數

timezone (時區)

要使用的時區。

locale (地區設定)

要使用的地區設定,或 null 以使用 預設地區設定

回傳值

建立的 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"

另請參閱

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top