JavaScript–Adding months or days to a date

Goal:

Add moths or days (or other increments) to a date in JavaScript.

Solution:

var current = new Date();

var threeMonthsInTheFuture =  new Date(new Date(current).setMonth(current.getMonth() + 3));

for days use:

getDate()

for hours use:

getHours().

and so on….

New on Geeks with Blogs