3

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.

Arthur
  • 87
  • 6
  • [The output is technically correct.](https://stackoverflow.com/q/66255217/5133585) Do you have a desired output in mind? What does your frontend actually expect? You're giving your frontend the server's system timezone. That doesn't look right... Should the front end care about the server's system timezone at all? If not, you can just use an `Instant`. – Sweeper Aug 31 '21 at 08:56
  • See also [this](https://stackoverflow.com/questions/66456630/different-values-when-converting-instant-to-localdatetime/66456985#66456985), where I listed all the time zone changes from 1700 to 2000 that are recorded in tzdb. – Sweeper Aug 31 '21 at 09:00

2 Answers2

7

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:

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
5

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194