18-04-2022 07:56 PM - edited 18-04-2022 08:00 PM
var d2=new Date("Thu Mar 31 2022 00:00:00");//2022-03-31
d2.setMonth(3);//set April
console.log(d2);//Become May 2022-05-01
Output result:
Sun May 01 2022 00:00:00 GMT+0800 (中国标准时间)
Solved! Go to Solution.
18-04-2022 10:26 PM
I think I know this one: 31 April 2022 is not a valid date, so Firefox rolls forward to a valid date based on the shortfall of days in the selected month compared with the original month.
Another example:
var d2=new Date("Thu Mar 31 2022 00:00:00"); //2022-03-31
d2.setMonth(1); //set February
console.log(d2); //expect 2022-03-03If you need to toll back to the last date of the "set" month in this situation, there probably are good code examples on StackOverflow or other sites for that.
18-04-2022 10:26 PM
I think I know this one: 31 April 2022 is not a valid date, so Firefox rolls forward to a valid date based on the shortfall of days in the selected month compared with the original month.
Another example:
var d2=new Date("Thu Mar 31 2022 00:00:00"); //2022-03-31
d2.setMonth(1); //set February
console.log(d2); //expect 2022-03-03If you need to toll back to the last date of the "set" month in this situation, there probably are good code examples on StackOverflow or other sites for that.
18-04-2022 11:04 PM
Thank you very much for your advice. I'll try.