PHP Conference Japan 2024

IntlCalendar::setTimeZone

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

IntlCalendar::setTimeZone設定此日曆使用的時區

說明

物件導向風格

public IntlCalendar::setTimeZone(IntlTimeZone|DateTimeZone|字串|null $timezone): 布林值

程序風格

intlcal_set_time_zone(IntlCalendar $calendar, IntlTimeZone|DateTimeZone|string|null $timezone): bool

為此日曆定義新的時區。物件表示的時間會被保留,但欄位值可能會因此改變。

參數

calendar

一個 IntlCalendar 實例。

timezone

此日曆要使用的新時區。可以透過以下方式指定:

返回值

成功時返回 true,失敗時返回 false

範例

範例 #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)

新增註釋

使用者貢獻的註釋

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