在PHP5中查找区域设置日期表示形式 [英] Finding locale date representation in PHP5

查看:65
本文介绍了在PHP5中查找区域设置日期表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站根据用户设置或浏览器设置(用户尚未设置其首选项)更改其区域设置。我使用的是amline图表,尤其是股票图表,它要求日期格式为 MM / DD / YYYY或 DD-MM-YYYY,所以我想让图表知道如何理解日期。有多种方法来设置日期格式,具体取决于计算机的语言环境,但是我找不到获取语言环境格式的方法(如上所述)。

my site changes its locale dependent upon either user settings or browser settings (where the user hasn't set their preference). I am using amline charts, the stock chart specifically, which requires the date format in 'MM/DD/YYYY' or 'DD-MM-YYYY', I guess so the chart knows how to understand the dates. There are many ways to format a date dependent upon the computer locale, however I can't find a way to get the locale format (as above).

推荐答案

Zend Framework 带有 Zend_Locale 类,该类又访问 Unicode语言环境数据标记语言(LDML)。这些包含许多其他内容,例如本地化的日期格式。请查看 Unicode通用语言环境数据存储库(CLDR)

The Zend Framework comes with a Zend_Locale class which in turn accesses a bunch of XML files in Unicode Locale Data Markup Language (LDML). Those contain, among lots of other things, localized date formats. Take a look at the Unicode Common Locale Data Repository (CLDR) for more information.

德语的XML文件将包含

As an example, the XML file for German would contain stuff like

<dateFormats>
    <dateFormatLength type="full">
        <dateFormat>
            <pattern>EEEE, d. MMMM yyyy</pattern>
        </dateFormat>
    </dateFormatLength>
    <dateFormatLength type="long">
        <dateFormat>
            <pattern>d. MMMM yyyy</pattern>
        </dateFormat>
    </dateFormatLength>
    <dateFormatLength type="medium">
        <dateFormat>
            <pattern>dd.MM.yyyy</pattern>
        </dateFormat>
    </dateFormatLength>
    <dateFormatLength type="short">
        <dateFormat>
            <pattern>dd.MM.yy</pattern>
        </dateFormat>
    </dateFormatLength>
</dateFormats>

现在,我还没有使用过它,但是通过短暂浏览它,我猜想 Zend_Locale_Data :: getContent()是您的朋友,应该给您所有您需要的信息。

Now, I haven't used this myself, but from briefly browsing through it I'd guess that Zend_Locale_Data::getContent() is your friend and should give you all the information you need.

如果您不这样做不想使用ZF,您可以直接使用您选择的XML解析器直接访问这些文件(您可能会在 unicode.org 上找到XML文件)。

If you don't wanna use ZF you can just access these files directly with the XML parser of your choice (you can probably find the XML files somewhere on unicode.org).

这篇关于在PHP5中查找区域设置日期表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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