I ran into a situation recently which required me to parse a string into a Date object in Flex. After some searching I found that there’s a wonderful little method in the DateFormatter class called parseDateString. Unfortunately, that method is protected and I couldn’t gain access to it. Luckily, I came accross a blog post that provided a wonderful solution: http://flex2colombia.wordpress.com/2007/02/18/dateformatter-parsedatestring-replacement/
The basis is that the Date class has a static method for parsing dates (parse()) which accepts a single String as a parameter. Here is an example:
var dateString:String = "Tue Jul 29 13:40:56 GMT-0500 2008";
var d:Date = new Date(Date.parse(dateString));
Just like that, you have a Date object to work with in Flex.
The following string formats are acceptable (all of which are recognized by Flex as a Date)
- MM/DD/YYYY HH:MM:SS TZD
- HH:MM:SS TZD Day Mon/DD/YYYY
- Mon DD YYYY HH:MM:SS TZD
- Day Mon DD HH:MM:SS TZD YYYY
- Day DD Mon HH:MM:SS TZD YYYY
- Mon/DD/YYYY HH:MM:SS TZD
- YYYY/MM/DD HH:MM:SS TZD
