I think issue you are facing is to do with differences between Chromium based browsers and the Gecko based firefox. Thus they handle your string a little differently from each other. As for converting a string into a Date object, the only way I can think of is by parsing it, ie passing it into Date
's constructor (as you have done).
Here is how I would solve this issue so it works in all browsers (by using the built-in methods inside the Date object).
const myDate = new Date();
myDate.setFullYear(2001);
myDate.setUTCMonth(0);
myDate.setUTCDate(31);
myDate.setUTCHours(0);
myDate.setUTCMinutes(0);
myDate.setUTCSeconds(0);
myDate.setUTCMilliseconds(0);
console.log(myDate); // 2001-01-31T02:00:00.000Z
// Now add a year:
const oldYear = myDate.getFullYear();
myDate.setFullYear(oldYear + 1);
// Results:
console.log("Expected result: year is 2002");
console.log(myDate); // Year is 2001 + 1 = 2002
Of course in your use case you may want to add hours, months or any other amount of time, so you can adapt accordingly.