0

I'm developing my mobile app with API. Binding datetime gives me error java.time.format.DateTimeParseException: Text '2022-12-16T00:00:00+03:00' could not be parsed, unparsed text found at index 19. Please help me format this weird date

fun formatDateOfReview(dateOfReview: String?): String? {
    val localDate = LocalDateTime.parse(dateOfReview)
    return localDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))
}
1
  • 1
    @jhamon that pattern is not used to parse the input but rather to format it as date only. Commented Dec 16, 2022 at 13:48

1 Answer 1

2
2022-12-16T00:00:00+03:00

That is a combined date-time with a time zone in ISO 8601 format.

LocalDateTime.parse(dateOfReview)

LocalDateTime is "A date-time without a time-zone in the ISO-8601 calendar system" (emphasis added).

Please use OffsetDateTime instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer. Unfortunately, that Wikipedia article uses the words “time zone” where it should use “offset”. The +03:00 is an offset from UTC, not a time zone. A time zone is a named history of the past, present, and future changes to the offset used by the people of a particular region, as decided by their politicians. The time zone has a name in the format of continent/region, such as Africa/Nairobi, Europe/Helsinki, and Indian/Mayotte.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.