php以特定格式显示日期,php获取区域设置特定的日期格式

您可以使用

Intl PHP扩展来根据所选的区域设置格式化日期:

$locale = 'nl_NL';

$dateObj = new DateTime;

$formatter = new IntlDateFormatter($locale,

IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);

echo $formatter->format($dateObj);

如果您只是想获得用于格式化日期的模式,那么IntlDateFormatter::getPattern就是您所需要的.

手册中的示例:

$fmt = new IntlDateFormatter(

'en_US',

IntlDateFormatter::FULL,

IntlDateFormatter::FULL,

'America/Los_Angeles',

IntlDateFormatter::GREGORIAN,

'MM/dd/yyyy'

);

echo 'pattern of the formatter is : ' . $fmt->getPattern();

echo 'First Formatted output is ' . $fmt->format(0);

$fmt->setPattern('yyyymmdd hh:mm:ss z');

echo 'Now pattern of the formatter is : ' . $fmt->getPattern();

echo 'Second Formatted output is ' . $fmt->format(0);

这将输出:

pattern of the formatter is : MM/dd/yyyy

First Formatted output is 12/31/1969

Now pattern of the formatter is : yyyymmdd hh:mm:ss z

Second Formatted output is 19690031 04:00:00 PST

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值