Date Format of a text property of a <Label>

2626
5
06-09-2010 02:02 PM
JeffPerkins
New Contributor III
I have a query that binds the data from Date field to a component in a <Label> through a text property.  How do I format the date?  I've tried DateFormatter with no success.  Any ideas?   The REST response with Thu Jun 03 18:13:12 CDT 2010.  I would like it to response with Jun 03, 2010 18:13.

<mx:DateFormatter id="time" formatString="MMM,DD,YY"/>
<mx:Component className="MyInfoWindowRenderer">
<mx:Label text="Date:"/>
            <mx:Label text="{time.format(data.DateTimeStamp}" fontWeight="bold"/>
Tags (2)
0 Kudos
5 Replies
Drew
by
Occasional Contributor III
You were very close.
In your sample you had a syntax error and the date format was a little off from what you wanted.
Below is the code that should get you the correct value. (Replace my hard coded date with your data.)

<mx:DateFormatter id="time" formatString="MMM DD,YYYY H:NN"/>
<mx:Label text="Date:"/>
<mx:Label text="{time.format('Thu Jun 03 18:13:12 CDT 2010')}" fontWeight="bold" y="10" width="318"/> 


You can find more info on the  Flex 3.5 DateFormatter here:
http://livedocs.adobe.com/flex/3/langref/mx/formatters/DateFormatter.html

Drew
0 Kudos
JeffPerkins
New Contributor III
Thanks Drew.  I think the format is fine.  The Component has a problem with instantiating the property "time"? 

I can get this to work thru a datagrid  using  the labelFunction but not a Component?
0 Kudos
DasaPaddock
Esri Regular Contributor
The Component tag defines a new scope. It's like have a separate mxml file, but putting it inline. Try moving the DateFormatter inside the Component.

Reference:
http://livedocs.adobe.com/flex/3/langref/mxml/component.html
0 Kudos
deleted-user-rQoEFM5qzbHE
New Contributor II
I tried to move the DateFormatter inside of the component, but get an error that says <mx:VBox> is not allowed to follow </mx:DateFormatter>. I was trying to use code from one of the samples.

<esri:infoWindowRenderer>
     <fx:Component>
      <mx:DateFormatter id="myDateFormatter" formatString="DD/MM/YY"/>
            
      <mx:VBox backgroundColor="0xffffff"
         color="0x444444"
         label="Crash Attributes">
       <mx:Label text="Severity: {data.SEVERITY_T}"/>
       <mx:Label text="Date: {myDateFormatter.format(data.DATE)}"/>
       <mx:Label text="Speed Induced: {data.SPD_IND}"/>
      </mx:VBox>
     </fx:Component>
    </esri:infoWindowRenderer>


I also tried to move the DateFormatter line elsewhere but get similar errors, except in relation to what comes either directly before or after.
0 Kudos