Jquery / Javascript - Add years to date variable

后端 未结 6 1498
耶瑟儿~
耶瑟儿~ 2021-02-19 06:05

I have a small trouble that would be great to have some help with. I am creating a small form that I want to take a current date formatted \'dd/mm/yyyy\' and add a

6条回答
  •  时光说笑
    2021-02-19 06:54

    A quick and easy solution :

    var myDate = new Date();
    myDate.setFullYear(myDate.getFullYear() + nbYearsToAdd);
    

    "nbYearsToAdd" can be negative.

提交回复
热议问题