IntlDateFormatter::getCalendar()函数是PHP中的内置函数,用于返回用于IntlDateFormatter对象的日历类型。
用法:
- 面向对象的样式:
int IntlDateFormatter::getCalendar( void )
- 程序风格:
int datefmt_get_calendar( IntlDateFormatter $fmt )
参数:该函数接受单个参数$fmt,该参数保存格式化程序的资源。
返回值:此函数返回格式化程序使用的日历类型。格式化程序对象是IntlDateFormatter::TRADITIONAL或IntlDateFormatter::GREGORIAN。
以下示例程序旨在说明PHP中的IntlDateFormatter::getCalendar()函数:
程序1:
<?php
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
// Get the calendar type
echo 'Calendar of formatter: '
. datefmt_get_calendar($formatter) . "\n";
// Get the format of date/time value as a string
echo "Formatted calendar output: "
. datefmt_format( $formatter , 0) . "\n\n";
// Set the calendar type used by the formatter
datefmt_set_calendar($formatter,
IntlDateFormatter::GREGORIAN);
// Get the calendar type
echo 'Calendar of formatter: '
. datefmt_get_calendar($formatter) . "\n";
// Get the format of date/time value as a string
echo "First Formatted output is "
. datefmt_format( $formatter , 0);
?>
输出:
Calendar of formatter: 0 Formatted calendar output: 01/01/1970 Calendar of formatter: 1 First Formatted output is 01/01/1970
程序2:
<?php
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
// Get the calendar type
echo 'Calendar of formatter: '
. $formatter->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
相关用法
- PHP IntlDateFormatter format()用法及代码示例
- PHP IntlDateFormatter getDateType()用法及代码示例
- PHP IntlDateFormatter formatObject()用法及代码示例
- PHP cos( )用法及代码示例
- d3.js d3.set.has()用法及代码示例
- PHP Ds\Map put()用法及代码示例
- PHP each()用法及代码示例
- CSS var()用法及代码示例
- PHP pos()用法及代码示例
- PHP sin( )用法及代码示例
- p5.js int()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | IntlDateFormatter getCalendar() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。