I'm trying to parse the below processingdate so that I can eventually end up with a date of format 2020-11-10T10:43:07+00:00. How can I amend the below to produce this?
String processingDate = "2020-11-24";
LocalDateTime dt =
LocalDateTime.of(
LocalDate.parse(
processingDate, DateTimeFormatter.ISO_DATE),
LocalTime.now());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssXXX");
OffsetDateTime dateTime = OffsetDateTime.parse(dt.format(formatter));
System.out.println(dateTime);
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds
A local datetime doesn't contain any concept of zones or offsets. You are trying to print the offset to a string by using XXX at the end of the pattern.
But anyway, there is no need to go from a LocalDateTime -> String -> OffsetDateTime.
Just do
dt.atOffset(ZoneOffset.UTC)
or whatever other offset you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With