Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 786
Arthur Avatar asked Sep 18 '25 22:09

Arthur


2 Answers

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:

  • Why is subtracting these two times (in 1927) giving a strange result?
  • DateFormatter gives weird timezone for very old dates
  • Providing date string with offsets (+0530) vs specifying timezone separately in display name (Asia/Calcutta)
  • Java OffsetDateTime returning wrong offset
like image 133
MC Emperor Avatar answered Sep 21 '25 10:09

MC Emperor


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.

like image 25
Jon Skeet Avatar answered Sep 21 '25 10:09

Jon Skeet