views:

77

answers:

1

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

thanks in advance.

+1  A: 

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

n3rd
CLDR is the best resource for getting locale information.
shadowhand