I am trying to get Java to read in a date formatted as follows: Thu Mar 8 13:33:25 2012 But getting an unparseable exception. Here's the code:
SimpleDateFormat formatter2 = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.ENGLISH);
String currentDate = "Thu Mar 8 13:33:25 2012";
Date date2 = formatter.parse(currentDate);
It throws the following exception: Exception in thread "main" java.text.ParseException: Unparseable date: "Thu Mar 8 13:33:25 2012"
Could someone help me out please? I've tried changing the "d" to "dd" but still doesn't work.
You are not using formatter2
variable as specified in your example.
Your code works when using formatter2
.
SimpleDateFormat formatter2 = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.ENGLISH);
String currentDate = "Thu Mar 8 13:33:25 2012";
Date date2 = formatter2.parse(currentDate);
System.out.println(date2);
Result:
Thu Mar 08 13:33:25 CAT 2012