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.

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top