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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。