I need Date in IST format so here I am trying to pass the date into three formats, first format gives the correct result but I need the second and third format where the year is passed in the last two digits but if the digits are less then 50 it's giving correct result if it is more then 50 it's giving 1950 as year, in my code I need it to pass as two digits only.
Basically, I need the date format as dd-mm-yy or dd/mm/yy
console.log(new Date(
`04/1/2050`
))// correct
console.log(new Date(
`04/1/50`
))// false
console.log(new Date(
`04/1/40`
))// correct
Following are the rules from ECMA (https://262.ecma-international.org/11.0/#sec-date-constructor)
If 0 ≤ yi ≤ 99, let yr be 1900 + yi; otherwise, let yr be y.
So this
console.log(new Date(
`04/1/40`
))
// 1940-03-31
I guess Browser's are taking liberty in this rule. And changed this rule to something like
If 0 ≤ yi ≤ 49, let yr be 2000 + yi
You can use same logic in your code too. But make sure it is implemented same way in every browser.