(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)
IntlCalendar::setTimeZone — 設定此日曆使用的時區
物件導向風格
程序風格
$calendar
, IntlTimeZone|DateTimeZone|string|null $timezone
): bool為此日曆定義新的時區。物件表示的時間會被保留,但欄位值可能會因此改變。
calendar
一個 IntlCalendar 實例。
timezone
此日曆要使用的新時區。可以透過以下方式指定:
null
,在這種情況下,將使用預設時區,如 ini 設定 date.timezone 中指定,或透過 date_default_timezone_set() 函式設定,並由 date_default_timezone_get() 函式返回。
一個 IntlTimeZone 物件,將直接使用。
一個 DateTimeZone 物件。將會提取其識別符號並建立一個 ICU 時區物件;時區將由 ICU 的資料庫支援,而不是 PHP 的。
一個 字串,它應該是一個有效的 ICU 時區識別符號。請參閱 IntlTimeZone::createTimeZoneIDEnumeration()。也接受原始偏移量,例如 "GMT+08:30"
。
範例 #1 IntlCalendar::setTimeZone()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'es_ES');
$cal = new IntlGregorianCalendar(2013, 5 /* 五月 */, 1, 12, 0, 0);
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(瞬間 {$cal->getTime()})\n";
$cal->setTimeZone(IntlTimeZone::getGMT());
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(瞬間 {$cal->getTime()})\n";
$cal->setTimeZone('GMT+03:33');
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(瞬間 {$cal->getTime()})\n";
以上範例將輸出
sábado, 1 de junio de 2013 12:00:00 Hora de verano de Europa occidental (instant 1370084400000) sábado, 1 de junio de 2013 11:00:00 GMT (instant 1370084400000) sábado, 1 de junio de 2013 14:33:00 GMT+03:33 (instant 1370084400000)