2024 年 PHP 日本會議

IntlDateFormatter::getCalendar

datefmt_get_calendar

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

IntlDateFormatter::getCalendar -- datefmt_get_calendar取得 IntlDateFormatter 使用的曆法類型

說明

物件導向風格

public IntlDateFormatter::getCalendar(): int|false

程序式風格

datefmt_get_calendar(IntlDateFormatter $formatter): int|false

參數

formatter

格式化器資源

回傳值

格式器使用的曆法類型。可以是 IntlDateFormatter::TRADITIONALIntlDateFormatter::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

參見

新增註解

使用者貢獻的註解

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