IntlDateFormatter::getDateType()函数是PHP中的内置函数,用于获取用于IntlDateFormatter对象的日期类型。
用法:
面向对象的样式:int IntlDateFormatter::getDateType( void )
程序风格:int datefmt_get_datetype( IntlDateFormatter $fmt )
参数:此函数使用单个参数$fmt,该参数保存格式化程序的资源。
返回值:此函数返回格式化程序的当前日期类型值。
以下示例程序旨在说明PHP中的IntlDateFormatter::getDateType()函数:
程序1:
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
// Get the date/type formatter type
echo 'Calendar of formatter: '
. datefmt_get_datetype($formatter) . "\n";
// Get the format of date/time value as a string
echo "Formatted calendar output: "
. datefmt_format( $formatter , 0) . "\n\n";
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL
);
// Get the date/type formatter type
echo 'Calendar of formatter: '
. datefmt_get_datetype($formatter) . "\n";
// Get the format of date/time value as a string
echo "Formatted calendar output: "
. datefmt_format( $formatter , 0);
?>
输出:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970
Calendar of formatter: 3
Formatted calendar output: 1/1/70, 5:30 AM
程序2:
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
// Get the date/type formatter type
echo 'Calendar of formatter: '
. $formatter->getDateType() . "\n";
// Get the format of date/time
// value as a string
echo "Formatted calendar output: "
. $formatter->format(0) . "\n\n";
// Create a date formatter
$formatter = datefmt_create(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Asia/Kolkata',
IntlDateFormatter::TRADITIONAL
);
// Get the date/type formatter type
echo 'Calendar of formatter: '
. $formatter->getDateType() . "\n";
// Get the format of date/time
// value as a string
echo "Formatted calendar output: "
. $formatter->format(0);
?>
输出:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970
Calendar of formatter: 3
Formatted calendar output: 1/1/70, 5:30 AM