PHP语言环境de_DE返回英语语言环境

时间:2018-11-12 14:26:08

标签: php apache ubuntu locale

我在Ubuntu系统上使用Apache和php 7。安装德语语言环境并运行locale -a来检查已安装的语言环境后,我得到了C, C.UTF-8, de_DE, de_DE@euro, de_DE.iso88591, de_DE.iso885915@euro, de_DE.utf8, deutsch, en_US.utf8, german, POSIX。我还使用sudo update-locale更新了语言环境。但是使用php代码

setlocale(LC_ALL,'de_DE');
echo date("F", strtotime("2018-10-10"));

它将返回英文“ October”,而不是德语“ Oktober”。我不知道该怎么办...我也重新启动了Apache ...但是什么也没发生。

1 个答案:

答案 0 :(得分:2)

date()函数不会监听语言环境-这将仅以英语返回值。

date()文档中,

  

要用其他语言格式化日期,应使用setlocale()和strftime()函数,而不要使用date()。

您需要改用strftime()

setlocale(LC_ALL,'de_DE');
echo strftime("%B", strtotime("2018-10-10"));
相关问题