2

I'm using Date.now() to get the current date.

I then need to add 30 days to this.

How can I do this?

Would I just work out how many seconds in 30 days, then add this on?

panthro
  • 22,779
  • 66
  • 183
  • 324

2 Answers2

1

var d = new Date();
console.log(d);

d.setDate(d.getDate() + 30);
console.log(d);
Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46
0

Date.prototype.getDate returns current date day number. Date.prototype.setDate set date number of given date to value passed to it. If value exceeds normal date range of month date extra value will handle needed math and change month (or year if necessary) and shows correct result.

var date = new Date;

date.setDate(date.getDate() + 30);
console.log(new Date, date);
Morteza Tourani
  • 3,506
  • 5
  • 41
  • 48