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"
1
  • Please search StackOverflow before posting. These basic date-time questions have been answered many times over already. Commented Mar 18, 2016 at 15:58

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.