Jean-Paul
Jean-Paul

Reputation: 21150

Parsing date with SimpleDateFormat

Why does the following give an error:

    DateFormat formatter1 = new SimpleDateFormat("E, MMM d");
    formatter1.setTimeZone(TimeZone.getTimeZone("America/New_York"));

    formatter1.parse("Tue, Nov 26");

I don't get why it isn't working.

Upvotes: 0

Views: 50

Answers (1)

Alexis C.
Alexis C.

Reputation: 93842

You should set a Locale to your formatter where months are spelt in English, otherwise it's using your default Locale :

SimpleDateFormat(String pattern)

Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default locale.

I.e :

DateFormat formatter1 = new SimpleDateFormat("E, MMM d", Locale.US);

Upvotes: 4

Related Questions