Unable to obtain ZonedDateTime from TemporalAccessor when parsing a Date

前端 未结 2 513
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 07:53

With Java 1.8.0_51 the following code (taken from Unable to obtain OffsetDateTime from TemporalAccessor)

DateTimeFormatter formatter = DateTimeFormatter.ofPa         


        
2条回答
  •  萌比男神i
    2020-12-16 08:26

    The Java 8 java.time.* package is a very strict package. It doesn't allow flexibility between types and inputs - if you want a ZonedDateTime object, you must construct it from an input that has a time zone, a date & a time.

    If you want to use just a date to construct an object it has to be of a type that doesn't have a time field, specifically, LocalDate.

提交回复
热议问题