Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2023-07-12 of type java.time.format.Parsed
时间: 2024-04-12 09:28:33 浏览: 7
这个错误通常出现在使用Java 8的`java.time.LocalDateTime`类时,尝试从一个格式不正确的字符串解析日期和时间。根据您提供的错误消息,看起来您尝试将一个空的`TemporalAccessor`对象解析为`LocalDateTime`对象。这可能是因为解析器无法从空字符串中获取日期和时间信息。
为了解决这个问题,您可以确保您提供的日期和时间字符串符合`java.time.LocalDateTime`的预期格式,然后再进行解析。您可以使用`java.time.format.DateTimeFormatter`类来指定正确的格式,例如:
```java
String dateTimeString = "2023-07-12T00:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
LocalDateTime localDateTime = LocalDateTime.parse(dateTimeString, formatter);
```
在这个示例中,日期和时间字符串的格式与ISO_LOCAL_DATE_TIME模式匹配,因此我们使用`DateTimeFormatter.ISO_LOCAL_DATE_TIME`来创建一个解析器。然后,我们使用`LocalDateTime.parse()`方法将字符串解析为`LocalDateTime`对象。
确保在使用`parse()`方法之前,您提供的日期和时间字符串是符合指定格式的,这样就可以避免该错误的出现。