PDA

View Full Version : Getting and formatting a Date Object?


jfoley
05-11-2010, 05:50 PM
I'm using a datagrid and one of the columns have a labelFunction tied to it. The data that is passed to my labelFunction contains 'lastUpdated' which has a string in this format: Thu Feb 04 05:31:10 GMT 2010

Which, is obviously a date object. I'm trying to reformat the date to be mm/dd/yyyy.

I'm currently trying this to no avail:


private function formatDate(item:Object, column:DataGridColumn):String
{
var itemDate:Date = item.lastUpdated as Date;
return itemDate.getFullYear();
}


For some reason itemDate always equals null even though the data in the item object is there. Hence, the labelFunction bugs out. Any ideas?

Lemme know if I can provide any further info. Thanks!

nguyenkhanhhung
05-12-2010, 03:00 PM
<?xml version="1.0"?>
<!-- controls\date\DateChooserFormatter.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private function formatDate(date:Date):String {
return dfconv.format(date);
}
]]>
</mx:Script>
<mx:DateFormatter id="dfconv" formatString="YYYY/MM/DD"/>
<mx:DateField id="df" labelFunction="formatDate" parseFunction="null"/>
</mx:Application>

NoobsArePeople2
05-12-2010, 05:40 PM
itemDate being null indicates the cast to Date is failing, which would mean that lastUpdate isn't actually a Date object.

Put a breakpoint in there and see if lastUpdate really is a Date object.