Reputation: 1442
I am using FLEX 3.0 I want to convert string to Date. At first i just think its very easy for me but later its going to be very hard its a simple one but i can't convert that i have got an error. So please help me.
Hours in 24 hour format. if 7 hour than it shows 07. this one is same for minutes, seconds, date & month.
Here i am providing you the code that i have did till that time...
public function btn_click():void
{
var str:String = lblDate.text;
var d:Date = DateField.stringToDate(str,"YYY-MM-DD HH:NN:SS");
Alert.show(d.toString());
}
<mx:HBox height="5%" width="100%">
<mx:Label id="lblDate" text="2011-12-07 11:06:01" />
<mx:Button label="Click" click="{btn_click();}" />
</mx:HBox>
Please Help me as early as possible
Upvotes: 1
Views: 1877
Reputation: 2009
According to the documentation, the stringToDate
method can only parse patterns containing Y, M, D and delimiter and punctuation characters. So by using H,M and S, you specify invalid characters in the pattern, which in turn determine the method to return null
, that's why you get the error.
A more appropriate approach would be to use the DateFormatter
class, as illustrated in this post here.
Hope this was useful. Have a good day.
Upvotes: 2