OffsetDateTime does not parse correctly the time when sending a defined time

558 views Asked by At

OffsetDateTime does not correctly parse the time when a defined time is sent to me

I have a service with a timezone UTC +4:00

I am sent two possible cases in STRING:

1- 2022-03-30T11:22:33.44+04:00 
2- 2022-03-30T11:22:33.44+0400

but when I do a

DateTimeFormatter formatter = DateTimeFormatter
        .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS[xxx][xx][X]");

OffsetDateTime.parse("2022-03-30T11:22:33.44+04:00", formatter);

always returns me 2022-03-30T11:22:33.440

This is technically incorrect because my servers are in the same zone, so it should be: 2022-03-30T07:22:22:33.44Z

but whatever parse I do it doesn't work, is there any way to do it this way?

0

There are 0 answers