How to add months to a date in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To add months to a JavaScript Date, use the setMonth() method. JavaScript date setMonth() method sets the months for a specified date according to local time.


You can try to run the following code to add 2 months.

      <title>JavaScript setMonth Method</title>
         var dt = new Date("August 20, 2017 11:30:25");
         dt.setMonth( dt.getMonth() + 2 );
         document.write( dt );
Updated on 16-Jan-2020 06:49:08