我有以下代码:爪哇 - 抛出错误时的日期是无效的
SimpleDateFormat formatDDMMYYY = new SimpleDateFormat("dd/MM/yyyy");
Calendar quotationDay = Calendar.getInstance();
try {
quotationDay.setTime(formatDDMMYYY.parse("06/13/2015"));
} catch (ParseException e) {
throw new RuntimeException("Quotation date is in incorrect format.");
}
的日期“2015年6月13日”不正确,因为没有13个月。 Java会在2016年自动解析它到下个月。有什么办法可以防止这种情况发生并抛出异常吗?
可能更好:http://stackoverflow.com/questions/15336200/why-does-simpledateformat-parse-incorrect-date – assylias