I would like to parse a date. My String date is \"Thu Jan 19 2012 08:00 PM\". And my code to parse is:
format = new SimpleDateFormat(\"EEE MMM dd yyyy hh:mm
Try below code... Tested and worked
String dateStr = "Thu Jan 19 2012 01:00 PM";
DateFormat readFormat = new SimpleDateFormat( "EEE MMM dd yyyy hh:mm aaa");
DateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = readFormat.parse( dateStr );
} catch ( ParseException e ) {
e.printStackTrace();
}
String formattedDate = "";
if( date != null ) {
formattedDate = writeFormat.format( date );
}
System.out.println(formattedDate);
Output is 2012-01-19 13:00:00
Cheers!!! Happy to help!!!