문제

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