简体   繁体   English

解析日期时出现ParseException

[英]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. 最可能的原因是NOV在默认语言环境中不是有效月份。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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