简体   繁体   中英

ParseException when parsing a date

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM