为什么以下内容会出错:
DateFormat formatter1 = new SimpleDateFormat("E, MMM d");
formatter1.setTimeZone(TimeZone.getTimeZone("America/New_York"));
formatter1.parse("Tue, Nov 26");
我不明白为什么它不起作用。
答案 0 :(得分:4)
您应该为格式化程序设置一个Locale
,其中月份拼写为英文,否则使用您的默认Locale
:
SimpleDateFormat(String pattern)
使用给定的模式和默认值构造
SimpleDateFormat
默认语言环境的日期格式符号。
I.e:
DateFormat formatter1 = new SimpleDateFormat("E, MMM d", Locale.US);