为什么下面的代码会抛出ParseException?
DateFormat df = new SimpleDateFormat("MMM d, yyyy");
String date = "Jan 1, 2011";
df.parse(date);
结果:
java.text.ParseException: Unparseable date: "Jan 1, 2011"
最佳答案
它与 @Gijs Overvliet 提到的 Locale 参数有关。 例如,我正在使用土耳其语语言环境,我的字符串应该相应地设置。
public static void main(String[] args) throws ParseException
{
DateFormat df = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
String date = "Oca 1, 2011";
df.parse(date);
}
关于java - java中的日期解析抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9293432/