首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]IntlDateFormatter::getLocale()函数—用法及示例

发布于 2025-04-28 15:50:32
0
12

函数名: IntlDateFormatter::getLocale()

适用版本: PHP 5 >= 5.3.0, PHP 7, PHP 8

用法: IntlDateFormatter::getLocale() 函数返回当前 IntlDateFormatter 对象的区域设置。

示例:

// 创建一个 IntlDateFormatter 对象
$dateFormatter = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/New_York',
    IntlDateFormatter::GREGORIAN
);

// 获取当前对象的区域设置
$locale = $dateFormatter->getLocale();

// 打印输出区域设置
echo "当前区域设置是:" . $locale;

输出:

当前区域设置是:en_US

在上面的示例中,我们首先创建了一个 IntlDateFormatter 对象,然后使用 getLocale() 函数获取了当前对象的区域设置。最后,我们打印输出了区域设置,得到了 "en_US"。这表示当前对象的日期格式将使用英语(美国)的语言和地区设置进行格式化。

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流