0

I'm retrieving a date in a HTML form, and I need to convert the string date into a java.util.Date so that it can be inserted into a database.

I've tried the following, but it always gives me a date in May 2008.

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date myDate = formatter.parse("27-11-2015");
SheppardDigital
  • 3,165
  • 8
  • 44
  • 74

2 Answers2

1
String string = "2015-11-27";
DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date);  
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

This was user error, my code should have been:

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date myDate = formatter.parse("27-11-2015");
SheppardDigital
  • 3,165
  • 8
  • 44
  • 74