我试图从import java.time.LocalDate;创建一个import java.time.LocalDate;实例,并遵循this
这是我的密码:
LocalDate sd= LocalDate.parse("2016-2-2");我面对着错误:
java.time.format.DateTimeParseException: Text '2016-2-2' could not be parsed at index 5
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)在另一个试图创建LocalDate实例的尝试中,我尝试了
LocalDate ed= new LocalDate("2016-2-4");但它再次抱怨:
The constructor LocalDate(String) is undefined发布于 2016-03-08 21:46:15
您需要使用格式化程序来解析java.time.LocalDate的单个字符日/月字段
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d");
LocalDate date = LocalDate.parse("2016-2-2", formatter);发布于 2016-03-08 21:45:19
LocalDate根本无法解析该字符串。使用SimpleDateFormat代替:https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
https://stackoverflow.com/questions/35878574
复制相似问题