Finding locale date representation in PHP5 [duplicate]

两盒软妹~` 提交于 2019-12-08 09:23:42

问题


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).


回答1:


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.

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>

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.

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).



来源:https://stackoverflow.com/questions/802765/finding-locale-date-representation-in-php5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!