If there is no straightforward solution, you can resort to regex:
private function formatDate(str:String):String
{
var regex:RegExp = /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/;
var matches:Object = regex.exec(str);
var date:Date = new Date(matches[1], Number(matches[2]) - 1, matches[3],
matches[4], matches[5], matches[6]);
var months:Array = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"];
var result:String = months[date.month] + " ";
result += date.date + ", " + date.fullYear + " ";
if(date.hours > 12)
result += (date.hours - 12) + ":" + date.minutes + ":" +
date.seconds + " pm";
else
result += date.hours + ":" + date.minutes + ":" + date.seconds + " am";
return result;
}
Explanation of the regex /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/
// Forward slashes - / - at the beginning and end are delimiters
\d+ /* One or more number of digits.
* Ideally it should be \d{n} (\d{4} - 4 digits),
* but I'm assuming that the input string would always be
* valid and properly formatted
*/
- and : //A literal hyphen/colon
\s //A whitespace (use \s+ to skip extra whitespaces)
() /* Parenthetic groups used to capture a string for using it later
* The return value of regex.exec is an array whose first element is
* the complete matched string and subsequent elements are contents
* of the parenthetic groups in the order they appear in the regex
*/