函数名:IntlDateFormatter::getDateType()
适用版本:PHP 5 >= 5.3.0, PHP 7, PHP 8
函数描述:IntlDateFormatter::getDateType() 函数用于获取当前日期格式化对象的日期类型。
用法:
public function IntlDateFormatter::getDateType(): int|false
参数:无
返回值:
- 当前日期格式化对象的日期类型,该值为整数。如果获取失败,则返回 false。
日期类型的取值及含义如下:
- IntlDateFormatter::NONE - 不包含日期部分。
- IntlDateFormatter::SHORT - 仅包含短日期部分。
- IntlDateFormatter::MEDIUM - 包含中等长度的日期部分。
- IntlDateFormatter::LONG - 包含长日期部分。
- IntlDateFormatter::FULL - 包含完整的日期部分。
示例:
$dateFormatter = new IntlDateFormatter("en_US", IntlDateFormatter::FULL, IntlDateFormatter::NONE);
$dateType = $dateFormatter->getDateType();
echo "Date type: " . $dateType;
输出:
Date type: 0
以上示例中,我们创建了一个日期格式化对象 $dateFormatter
,使用美国英语作为区域设置,日期类型为 FULL
,不包含时间部分。然后,我们调用 getDateType()
方法获取当前日期格式化对象的日期类型,并将其输出。在这个示例中,日期类型为 0
,代表 NONE
,即不包含日期部分。