我正在尝试在当前区域设置中输出日期时间值,但是在使用它并尝试 en_US 区域设置时,它似乎仍在使用 24 小时时间格式,而不是 5:13:17 PM .
例如这段代码:
setlocale(LC_TIME, 'en_US');
echo strftime("%c");
echo strftime("%x %X %p");
输出:
Wed Nov 12 17:23:17 2014
11/12/14 17:23:17 PM
我认为这可能是 ubuntu 服务器配置问题,但 locale -a 返回(除其他外):
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US
en_US.iso88591
en_US.utf8
有什么想法吗?
谢谢
更新
从我的 ubuntu 12.04LTS 服务器上的命令行:
>date --date='2014-11-13 16:21:42' +%X
04:21:42 PM
>locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
>sudo dpkg-reconfigure locales
Generating locales...
de_AT.UTF-8... up-to-date
de_BE.UTF-8... up-to-date
de_CH.UTF-8... up-to-date
de_DE.UTF-8... up-to-date
de_LI.UTF-8... up-to-date
de_LU.UTF-8... up-to-date
en_AG.UTF-8... up-to-date
en_AU.UTF-8... up-to-date
en_BW.UTF-8... up-to-date
en_CA.UTF-8... up-to-date
en_DK.UTF-8... up-to-date
en_GB.UTF-8... up-to-date
en_HK.UTF-8... up-to-date
en_IE.UTF-8... up-to-date
en_IN.UTF-8... up-to-date
en_NG.UTF-8... up-to-date
en_NZ.UTF-8... up-to-date
en_PH.UTF-8... up-to-date
en_SG.UTF-8... up-to-date
en_US.ISO-8859-1... up-to-date
en_US.UTF-8... up-to-date
en_ZA.UTF-8... up-to-date
en_ZM.UTF-8... up-to-date
en_ZW.UTF-8... up-to-date
Generation complete.
最佳答案
伙计们,我所要做的就是重新启动 apache(!),由于某种原因它需要重新加载语言环境..
我还需要将 .UTF8 附加到我的调用中,如下所示
setlocale(LC_TIME, 'en_US.UTF8');
谢谢大家,希望这对 future 的其他人有所帮助
关于PHP:格式化时间时 strftime 忽略 setlocale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26892901/