val dateFormatter= DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd")
.toFormatter()
val begin = (LocalDateTime.parse("2019-11-04", dateFormatter).atOffset(ZoneOffset.UTC)
.toInstant()).atZone(ZoneId.of(timeZoneIdentifier))
When I try to parse the date like this, i get the following error:
Text '2019-11-04' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: DateTimeBuilder[, ISO, null, 2019-11-04, null], type org.threeten.bp.format.DateTimeBuilder
Since
2019-11-04is ISO 8601 format andLocalDateand the other java.time classes parse ISO 8601 format as their default, you don’t need any explicit formatter. Just this:Assuming that
timeZoneIdentifierisEurope/Bucharestthe result is aZonedDateTimeof2019-11-04T02:00+02:00[Europe/Bucharest].You cannot parse your string into a
LocalDateTime. That would require not only a date but also a time of day, and as you know, your string contains only the former.Link: Wikipedia article: ISO 8601