Seblor
Seblor

Reputation: 7146

When will date.parse() change century for 2-digits year?

According to the compatibility notes on the Date.parse() method on MDN, dates with a 2-digits year (for example : '10/10/18') will be treated as 21th century if the year is under 50.

For example :

Date.parse('10/10/18'); // Oct 10 2018
Date.parse('10/10/68'); // Oct 10 1968

I was wondering if that rule will change, and if it does, when ?

Disclaimer : I know ISO 8601 format is recommended.

Upvotes: 1

Views: 532

Answers (1)

Robby Cornelissen
Robby Cornelissen

Reputation: 97302

The behavior is not dictated by the ECMAScript specification, which says about Date.parse():

The function first attempts to parse the format of the String according to the rules (including extended years) called out in Date Time String Format (20.3.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.

So, your question is unanswerable. It's completely implementation-dependent and at the discretion of the browser vendor.

Upvotes: 3

Related Questions