(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)
IntlDateFormatter::getCalendar -- datefmt_get_calendar — 取得 IntlDateFormatter 使用的曆法類型
物件導向風格
程序式風格
formatter
格式化器資源
格式器使用的曆法類型。可以是 IntlDateFormatter::TRADITIONAL
或 IntlDateFormatter::GREGORIAN
。失敗時返回 false
。
範例 #1 datefmt_get_calendar() 範例
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo '格式器的曆法為:' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo '現在格式器的曆法為:' . datefmt_get_calendar($fmt);
?>
範例 #2 物件導向範例
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo '格式器的曆法為:' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo '現在格式器的曆法為:' . $fmt->getCalendar();
?>
範例 #3 無效地區設定處理範例
<?php
try {
$fmt = new IntlDateFormatter(
'invalid_locale',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'dunno',
IntlDateFormatter::GREGORIAN,
);
$cal = $fmt->getCalendar();
} catch (\Error $e) {
// ...
}
?>
以上範例會輸出
calendar of the formatter is : 1 Now calendar of the formatter is : 0