views:

310

answers:

2

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"/>
+2  A: 

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.

sergiogx
`labelText = str[0] + " " + str[1] + " " + str[2] + " " + str[5];`
Amarghosh
A: 

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.

Ross Henderson
i believe the string i am passing it has to much data in it and the formatter cannot handle it. plus as zombiegx pointed out the date has words in it instead of numbers for month / day etc...
medoix
it shouldn't be a problem, really, for the date to have words if you're using a DateFormatter. It's easier if everything is numbers, but you can make a DateFormatter that uses strings. The DateFormatter has a helper object called a DateBase which contains info for day names and month names. You can create your own DateBase object, as well, if you need to. I don't have enough time to put up a meaningful chunk of code right now - but if I find some time soon, I will.
Ross Henderson