1
votes

I'm using the MX DateField control in Flex and want to display the date as 01 Jul 2011 or 01 July 2011. Does anyone know how to do this? I tried setting the formatString to "DD MMM YYYY" but it didn't work.

2

2 Answers

4
votes

This works:

<fx:Declarations>
    <mx:DateFormatter id="myDf" formatString="DD MMM YYYY"/>
</fx:Declarations>
<fx:Script>
    <![CDATA[
        private function formatDate(date:Date):String{
            return myDf.format(date);
        }
    ]]>
</fx:Script>
<mx:DateField id="dateField" labelFunction="formatDate" />

Found it in the LiveDocs at http://livedocs.adobe.com/flex/3/html/help.html?content=controls_12.html

However this does not explain why the formatString property on the component does not work properly. I can confirm that it does not work as expected.

Cheers

0
votes

I would use something like this:

<mx DateField id        = "dateField" 
              dayNames  ="["S", "M", "T", "W", "T", "F", "S"]"
              monthNames="["January", "February", "March", "April", "May",
                           "June", "July", "August", "September", "October", 
                           "November", "December"]" />

Since you mentioned 3 character month names, this is a good example. If you don't need the day names, of course, remove that line.

<mx DateField id        = "dateField" 
              dayNames  ="["S", "M", "T", "W", "T", "F", "S"]"
              monthNames="["Jan", "Feb", "Mar", "Apr", "May",
                           "Jun", "Jul", "Aug", "Sep", "Oct", 
                           "Nov", "Dec"]" 
           formatString = "DD MMM YYY" />

Hope this helps.