PHP:strftime在格式化时间时忽略setlocale
我试图在当前区域设置中输出日期时间值,但在使用它和尝试en_US区域设置(例如)时,它似乎仍然使用24小时时间格式,而不是下午5:13:17 例如,此代码:PHP:strftime在格式化时间时忽略setlocale,php,ubuntu,Php,Ubuntu,我试图在当前区域设置中输出日期时间值,但在使用它和尝试en_US区域设置(例如)时,它似乎仍然使用24小时时间格式,而不是下午5:13:17 例如,此代码: 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返回(除其他外):
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返回(除其他外):
有什么想法吗
谢谢
更新 从我的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');
谢谢大家,我希望这能在将来帮助其他人在Centos 6.5和Gentoo上对我有效。命令行上的
date+%X
显示了什么?有人认为这可能是系统依赖的行为。也许您使用的是UTF-8,我从某些方面推断,它将时钟切换为24小时。setlocale()的返回值是多少?@bishop我使用了“date--date='2014-11-13 16:21:42'+%X”,得到了“04:21:42 PM”,我在原始文件的底部添加了更多信息question@jeroen当我尝试setlocale(LC_TIME,'de_de')时,我得到了false,当我尝试setlocale(LC_-TIME,'en_-US')时,我得到的是false,当我尝试setlocale(LC_-TIME,'en_-NG')时,我得到的是“en_-NG”,我不知道为什么这一个有效,而其他的无效,请参阅我对上面原始问题的更新以了解更多服务器数据
setlocale(LC_TIME, 'en_US.UTF8');