Question

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.

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top