Arthur
Arthur

Reputation: 127

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.

Upvotes: 4

Views: 1452

Answers (2)

MC Emperor
MC Emperor

Reputation: 22997

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:

Upvotes: 7

Jon Skeet
Jon Skeet

Reputation: 1500675

My guess is that you're in the Asia/Kolkata time zone - which, according to the IANA time zone data, did indeed have an offset of +05:53:28 until 1854, and which didn't settle to +05:30:00 until 1905. So in 1799, the offset should (following the IANA data) be +05:53:28.

In other words, the problem is in your expectations rather than in Java.

Upvotes: 5

Related Questions