2

This is my method:

  @Test
  public void convertUpdateDateToDateTest() {
    String updateDate = "11-Dec-2015";

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");

    try {
      Date date = formatter.parse(updateDate);
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }

I don't understand why this is not working.

Exception:

java.text.ParseException: Unparseable date: "11-Dec-2015"
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
Marco Wagner
  • 434
  • 1
  • 4
  • 13
  • Please search StackOverflow before posting. These basic date-time questions have been answered many times over already. – Basil Bourque Mar 18 '16 at 15:58

1 Answers1

4

You can have a Locale different then English specified as your Java default one in which case parsing won't recognize English month names.

Try this:

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH);

IDEONE DEMO

MJar
  • 741
  • 9
  • 26
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331