-6

I'm having trouble formatting a custom String back to a Date object. What i have:

String customString = "October 14, 2015;

Date date = new Date();
SimpleDateFormat s = new SimpleDateFormat("MM-dd-yyyy");

try {
 date = s.parse(customString);
} catch (ParseException e) {
 e.printStackTrace();
}

I always get a unappeasable date exception. Any pointers of what i'm doing wrong is appreciated.

CodeGeass
  • 619
  • 2
  • 7
  • 20

2 Answers2

1

Your pattern must be: new SimpleDateFormat("MMM dd,yyyy");

For more informations about SimpleDateFormat see the javadoc

Jens
  • 67,715
  • 15
  • 98
  • 113
0

Read the docs, https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html.

The argument of the constructor should have the format of the date you want to input.

For instance, if you want the full month name should have "MMMMM".

Just make the following change and the program will work.

SimpleDateFormat s = new SimpleDateFormat("MMMMM dd, yyyy");