This question already has answers here:
Unable to obtain OffsetDateTime from TemporalAccessor
                                
                                    (2个答案)
                                
                        
                        
                            Unable to obtain LocalDateTime from TemporalAccessor when parsing LocalDateTime (Java 8)
                                
                                    (9个答案)
                                
                        
                                5个月前关闭。
            
                    
我有这段代码:

public static final String DATE_PATTERN = "yyyy-MM-dd";

    OffsetDateTime.parse(startTime, DateTimeFormatter.ofPattern(DateFormat.DATE_PATTERN)


但是解析时出现此错误:

java.time.format.DateTimeParseException: Text '2019-07-10' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2019-07-10 of type java.time.format.Parsed

最佳答案

ZonedDateTime


  ISO-8601日历系统中带有时区的日期时间,例如2007-12-03T10:15:30 + 01:00欧洲/巴黎。


LocalDate


  ISO-8601日历系统中没有时区的日期,例如2007-12-03。


由于您的字符串仅表示简单日期,因此请使用LocalDate

LocalDate date = LocalDate.parse(startTime, DateTimeFormatter.ISO_DATE);

10-05 17:47