Gaurav Sen
Gaurav Sen

Reputation: 39

Why do dates below the year 1906 show the time part incorrectly on parsing?

Shows time correctly: new Date("1906-01-01T15:00:00+05:30") => Mon Jan 01 1906 15:00:00 GMT+0530 (India Standard Time)

Incorrect Time new Date("0001-01-01T15:00:00+05:30") => Mon Jan 01 0001 15:23:28 GMT+0553 (India Standard Time)

Notice that time offset has changed - not sure why this is happening?

Incorrect time new Date("1905-01-01T15:00:00+05:30") => Sun Jan 01 1905 14:51:10 GMT+0521 (India Standard Time)

How do I show the time correctly in such scenarios?

Upvotes: 2

Views: 234

Answers (1)

sriharshay
sriharshay

Reputation: 63

British India did not adopt international Time standards until 1905. Till then the meridian passed through Allahabad. So, IST which is being given to you is technically correct. i.e., with offset +0521 So, IST was enforced on Jan 1, 1906. That's why if the date given falls after Dec 31, 1905, Offset of +0530 is used for IST. Basically, the date you give as the input is taken as the user's browser's time zone's time. So, even if you give an offset, it doesn't matter as the time is being taken as IST time of 1905 which has maybe had 0521 as an offset. and I think as the time being accepted, has a different offset, your offset does not work correctly. So, if you give the offset as "+0521", then you will be getting the time you desire, but with a 10s variation.

Upvotes: 2

Related Questions