出现了报错 经过反复测试发下如下问题
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("y-L-d"); // HH:mm:ss LocalDate parse1 = LocalDate.parse("2018-02-09", dateTimeFormatter);// 01:01:01 LocalDate parse2 = LocalDate.parse("2018-2-9", dateTimeFormatter);// 01:01:01 LocalDate parse3 = LocalDate.parse("2018-2-09", dateTimeFormatter);// 01:01:01 LocalDate parse4 = LocalDate.parse("2018-02-9", dateTimeFormatter);// 01:01:01 System.out.println(parse1.format(dateTimeFormatter)); System.out.println(parse2.format(dateTimeFormatter)); System.out.println(parse3.format(dateTimeFormatter)); System.out.println(parse4.format(dateTimeFormatter)); DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); try { // HH:mm:ss LocalDate parse5 = LocalDate.parse("2018-02-09", dateTimeFormatter2);// 01:01:01 System.out.println("parse5 ok " + parse5); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } try { LocalDate parse6 = LocalDate.parse("2018-2-9", dateTimeFormatter2);// 01:01:01 System.out.println("parse6 ok " + parse6); } catch (Exception e) { System.out.println(e.getMessage()); } try { LocalDate parse7 = LocalDate.parse("2018-2-09", dateTimeFormatter2);// 01:01:01 System.out.println("parse7 ok " + parse7); } catch (Exception e) { System.out.println(e.getMessage()); } try { LocalDate parse8 = LocalDate.parse("2018-02-9", dateTimeFormatter2);// 01:01:01 System.out.println("parse8 ok " + parse8); } catch (Exception e) { System.out.println(e.getMessage()); } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(format.parse("2018-02-09")); System.out.println(format.parse("2018-2-9")); System.out.println(format.parse("2018-2-09")); System.out.println(format.parse("2018-02-9"));从上面可以发下MM是需要和数量对应的mmm可以对应英文月份的缩写y L d都是可以匹配多个的,以后使用新版本的就用“y-L-d"就好了