Java SimpleDataFormat不一致分析错误
示例代码说明了这一点:Java SimpleDataFormat不一致分析错误,java,simpledateformat,Java,Simpledateformat,示例代码说明了这一点: private void parse() throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy"); Date started = sdf.parse("Sep/22/2004"); // this triggers: java.text.ParseException: Unparseable date: "May/2
private void parse() throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy");
Date started = sdf.parse("Sep/22/2004");
// this triggers: java.text.ParseException: Unparseable date: "May/23/2010"
Date ended = sdf.parse("May/23/2010");
}
不知道我还能补充什么。我试图解析“MMM/dd/yyyy”日期,但得到了不一致的异常行为。感觉好像我错过了一些明显的东西。这当然与地区有关。添加以下内容:
sdf.setDateFormatSymbols(DateFormatSymbols.getInstance(Locale.ENGLISH));
或者,也可以简单地使用区域设置声明它:
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy", Locale.ENGLISH);
@或者简单地说:
DateFormat sdf=newsimpledateformat(“MMM/dd/yyyy”,Locale.ENGLISH)
如果不想更改常规设置。DateFormat sdf=new SimpleDateFormat(“MMM/dd/yyyy”,Locale.US)代码>或者简单地说。非常感谢。@Guillaume:为什么不写下来作为答案呢?我能做到。我不太熟悉如何在网上发帖。