📜  PHP | IntlDateFormatter getCalendar()函数

📅  最后修改于: 2022-05-13 01:56:49.883000             🧑  作者: Mango

PHP | IntlDateFormatter getCalendar()函数

IntlDateFormatter::getCalendar()函数是PHP中的一个内置函数,用于返回用于 IntlDateFormatter 对象的日历类型。
句法:

  • 面向对象风格:
int IntlDateFormatter::getCalendar( void )
  • 程序风格:
int datefmt_get_calendar( IntlDateFormatter $fmt )

参数:此函数接受单个参数$fmt保存格式化程序的资源。
返回值:此函数返回格式化程序使用的日历类型。格式化程序对象是 IntlDateFormatter::TRADITIONAL 或 IntlDateFormatter::GREGORIAN。
下面的程序说明了PHP中的 IntlDateFormatter::getCalendar()函数:
方案一:

php


php
getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "Formatted calendar output: "
        . $formatter->format(0) . "\n\n";
 
// Set the calendar type used by the formatter
$formatter->setCalendar(IntlDateFormatter::GREGORIAN);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . $formatter->getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "First Formatted output is "
        . $formatter->format(0);
 
?>


输出:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970

Calendar of formatter: 1
First Formatted output is 01/01/1970

方案二:

PHP

getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "Formatted calendar output: "
        . $formatter->format(0) . "\n\n";
 
// Set the calendar type used by the formatter
$formatter->setCalendar(IntlDateFormatter::GREGORIAN);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . $formatter->getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "First Formatted output is "
        . $formatter->format(0);
 
?>
输出:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970

Calendar of formatter: 1
First Formatted output is 01/01/1970

参考: https://www. PHP.net/manual/en/intldateformatter.getcalendar。 PHP