javaoffsetdatetime

Java OffsetDateTime returning wrong offset


I have a Java Timestamp value like: 1799-12-31 19:03:58.0 And when I try to convert it into the OffsetDateTime using the code:

timestamp.toLocalDateTime().atZone(ZoneId.systemDefault()).toOffsetDateTime();

It gives me the output as:

1799-12-31T19:03:58+05:53:28

Which is not getting parsed at frontend (Angular's date pipe). But the same code returns the different offset for the timestamp: 2019-08-24 10:15:22.0 as:

2019-08-24T10:15:22+05:30

Which is valid and successfully gets parsed by Angular's date pipe.

I am not getting why it is returning different offset for the '1799-12-31 19:03:58.0' date.


Solution

  • Short answer: history.

    Judging by the weird 05:53:28 offset, your current zone is Asia/Calcutta ← well, this timezone has been renamed to Asia/Kolkata.

    Back in 1799, each city had its own local time, which is why this offset is strange. Timezones are often changed due to political decisions, and Java gets this data from the timezone data shipped along with each Java release.

    So those different offsets are actually correct.

    If your frontend cannot parse this strange offset, then you need to fix your frontend.


    More information and similar observations: