尽管时区正确,但PHP strftime输出格式错误 [英] PHP strftime outputs wrong format despite correct timezone

查看:65
本文介绍了尽管时区正确,但PHP strftime输出格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php.ini中将时区配置为欧洲/巴黎.当执行date_default_timezone_get()时,我会得到正确的值.

I configured my timezone to Europe/Paris in php.ini. When executing date_default_timezone_get() I do get the correct value.

然后,我希望strftime('%x', date())输出类似法国格式的 16 novembre 2018 .但是取而代之的是 11/16/2018 ,它看起来像美国格式.

Then, I expect strftime('%x', date()) to output something like 16 novembre 2018 which is the French format. But instead, I get 11/16/2018 which looks like the US format.

知道为什么吗?

推荐答案

时区对日期和时间的显示方式没有影响,因为您需要设置区域设置.语言环境名称没有标准,但幸运的是,PHP的 setlocale() 函数将采用多个语言环境名称,并在第一个成功的人.

The time zone has no effect on how dates and times are presented, for that you need to set the locale. There are no standards for locale names, but fortunately PHP's setlocale() function will take multiple locale names, stopping at the first successful one.

// just a few common name formats
setlocale(LC_TIME, ["fr_FR.utf8", "fr_FR@euro", "fr_UTF8", "fr_FR", "french"]);
echo strftime("%d %B %Y", time());

这篇关于尽管时区正确,但PHP strftime输出格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆