1

Hi I am trying to use org.threeten.bp library and format a date string to zonnedDateTime but it does not work.

   val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
        val aOne = ZonedDateTime.parse("2022-08-11", dateFormatter)

I am using import org.threeten.bp.* library.

error I get is

org.threeten.bp.format.DateTimeParseException: Text '2022-08-11' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: DateTimeBuilder[, ISO, null, 2022-08-11, null], type org.threeten.bp.format.DateTimeBuilder

could you suggest what I am doing wrong here please

Thanks R

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • 2
    what happens if you turn it into a localdate? You don't have time and zoneinformation. makes sense that it cannot construct a zoneddatetime from it. – Daniel Jacob Aug 11 '22 at 19:11
  • Tip of the day: paste your error message into your search engine. First remove any parts that are specific to the data you use like `'2022-08-11'`. – Ole V.V. Aug 13 '22 at 08:39
  • It would immediately seem that @DanielJacob is correct, a `LocalDate` would fit your data better. Have you got a reason for needing a `ZonedDateTime`? If so, what time zone and what time of day do you want? Sure it’s possible. – Ole V.V. Aug 13 '22 at 08:41

0 Answers0