{
try{
// see rfc822 [EEE,] dd MMM yyyy HH:mm::ss z
// assume 4 digit year
SimpleDateFormat format;
if ( date_str.indexOf( "," ) == -1 ){
format = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z", Locale.US );
}else{
format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US );
}
return( format.parse( date_str ));
}catch( ParseException e ){
String[] fallbacks =
{
"dd MMM yyyy HH:mm:ss z", // As above but laxer
"EEE dd MMM yyyy HH:mm:ss z", // As above but laxer
"EEE MMM dd HH:mm:ss z yyyy", // Fri Sep 26 00:00:00 EDT 2008
"EEE MMM dd HH:mm z yyyy", // Fri Sep 26 00:00 EDT 2008
"EEE MMM dd HH z yyyy", // Fri Sep 26 00 EDT 2008
"yyyy-MM-dd HH:mm:ss", // 2009-02-08 22:56:45
"yyyy-MM-dd", // 2009-02-08
};
// remove commas as these keep popping up in silly places
date_str = date_str.replace( ',', ' ' );
// remove duplicate white space
date_str = date_str.replaceAll( "(\\s)+", " " );
for (int i=0;i<fallbacks.length;i++){
try{
return( new SimpleDateFormat(fallbacks[i], Locale.US ).parse( date_str ));
}catch( ParseException f ){
}
}