ParseException when parsing a date

こ雲淡風輕ζ 提交于 2019-12-13 01:43:15

问题


I am running the following code:

DateFormat fullDate = new SimpleDateFormat("HHmmdd/MMMyy");
Date date = fullDate.parse("035627/NOV15");

and the following exception is thrown:

Exception in thread "main" java.text.ParseException: Unparseable date:"035627/NOV15

Any ideas, why the exception is thrown, while the format is validly stated?


回答1:


The likeliest reason is that NOV is not a valid month in your default Locale. This should fix the problem (adjust the Locale to match the language used for the month name):

DateFormat fullDate = new SimpleDateFormat("HHmmdd/MMMyy", Locale.ENGLISH);


来源:https://stackoverflow.com/questions/33960608/parseexception-when-parsing-a-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!