-1

From a rest application I get different times in UTC.

A few examples 2999-01-30T23:00:00.000Z or 1699-12-30T23:00:00.000Z.

I convert it to Time on the front end, using new Date(date) in JavaScript.

The problem is then in the resulting format.

new Date("2999-01-30T23:00:00.000Z") results in Thu Jan 31 2999 00:00:00 GMT+0100, as expected.

But new Date("1699-12-30T23:00:00.000Z") results in Wed Dec 30 1699 23:57:44 GMT+0057.

Why does it suddenly give me this output? Why is there this odd time shift?

I wonder what the problem is, whether anything exists to solve this? I could not find anything.

trincot
  • 317,000
  • 35
  • 244
  • 286
  • 1
    Hi Zdenek, Welcome to SO, few tips, 1. avoid strong language like you have used in the question 2. frame the question properly before posting, your tag says it's javascript but in question, it is mentioned Java. – Yash Karanke Dec 20 '19 at 08:05

1 Answers1

1

I'm guessing with a date from 1699, you are back in history where timezones were different. For example here in Denmark we switched to CET in 1894, so I get:

new Date("1893-12-31T00:00:00.000Z");
// Sun Dec 31 1893 00:50:20 GMT+0050 (Central European Standard Time)
new Date("1894-01-01T00:00:00.000Z");
// Mon Jan 01 1894 01:00:00 GMT+0100 (Central European Standard Time)
pjoe
  • 186
  • 1
  • 7
  • Indeed, in Belgium there is a 00:17 timezone difference noticeable in JavaScript for dates before 1 May 1892, 12:00. This corresponds to what is stated [here](https://www.timeanddate.com/time/zone/belgium/brussels?year=1892) – trincot Dec 20 '19 at 09:21