medoix
medoix

Reputation: 1179

Flex date formatting XML result

I am retrieving a twitter feed using a php file and it is returning the XML, however the date XML field is..

<created_at>Sun Nov 08 07:26:07 +0000 2009</created_at>

I am calling this inside flex from my

[Bindable] public var twitterData:XMLList;

using {data.created_at} how would I format this to read as a normal date? (i.e Sun Nov 08 2009) or similar.

EDIT:

i have done the following but now nothing is showing, i believe the dateformatter is only for dates whereas i have allot more info in the string.

<mx:DateFormatter id="formatDateTime" formatString="DD/MM/YYY" />
<mx:Label width="100%" text="{formatDateTime.format(data.created_at)}" fontWeight="bold" color="#FFAE00"/>

Upvotes: 1

Views: 970

Answers (2)

sergiogx
sergiogx

Reputation: 1582

You could use an array to split it by spaces:

private function formatedDate(date:String):String{
   var arr:Array = date.split(/\s/);
   return arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[5];
}

and then bind it to a label

<mx:Label text="{formatedDate(data.created_at)}" />

I've tried using DateFormatter and Date and I was unsuccesful, DateFormatter and Date both need a DD/MM/YYYY format for input string.

Upvotes: 2

Ross Henderson
Ross Henderson

Reputation: 1779

If you haven't already, you might take a look at the DateFormatter object. http://livedocs.adobe.com/flex/3/langref/

That lets you set up your own conversion from string input to date - just like what zombiegx suggests, but with a more flexibility. The initial conversion returns a string, but that can be converted to a Date object via the parseDateString method.

Upvotes: 0

Related Questions