PHP如何使用国际化日期? [英] How to get PHP to use internationalised dates?

查看:106
本文介绍了PHP如何使用国际化日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让PHP日期工作跨语言。语言代码将根据登录的用户语言设置提供。



我以为我可以这样做:

  setlocale(LC_ALL,'de_DE.UTF-8'); 
echo strftime('%A%B%Y');

但输出是:

  2011年4月3日星期三

而我预期的:

  Mittwoch 2011年4月

(四月与英文和德文相同)



这不是使用 strftime的正确方法函数?如果没有,是否有另一种方法?

解决方案

setlocale()返回一个值,可以是FALSE:


返回新的当前语言环境,或
FALSE如果您的平台上未实现区域设置功能

指定的区域设置不存在或
类别名称无效。


所以你需要检查返回值。



请注意,区域设置名称因平台和 de_DE.UTF-8 看起来像一个典型的Unix名称。是Unix服务器吗?如果是这样,请确保计算机实际上已安装了这样的区域设置。


I'm trying to get PHP dates to work cross language. The language code will be supplied according to the logged in user's language setting.

I thought I could do this:

setlocale(LC_ALL, 'de_DE.UTF-8');
echo strftime('%A %B %Y');

But the output is:

Wednesday April 2011

Whereas I would have expected:

Mittwoch April 2011

(April is the same in English and German)

Is this not the correct way to use the strftime function? If not, is there an alternative method?

解决方案

setlocale() returns a value, which can be FALSE:

Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.

So you need to check the return value.

Be aware that locale names vary depending on the platform and de_DE.UTF-8 looks like a typical Unix name. Is it a Unix server? If so, make sure that the computer actually has such locale installed.

这篇关于PHP如何使用国际化日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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