Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Set date 30 days from now

I need to set a date that would be 30 days from now taking into account months that are 28,29,30,31 days so it doesn't skip any days and shows exactly 30 days from now. How can I do that?

like image 711
Victor Avatar asked Oct 26 '11 19:10

Victor


People also ask

How can add 30 days to current date in jquery?

value = (date. getMonth() + 1) + '/' + date. getDate() + '/' + date. getFullYear();

What is JavaScript date now ()?

The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.

What is date now () format?

The date. now() method is used to return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Since now() is a static method of Date, it will always be used as Date. now().


1 Answers

The JavaScript "Date()" object has got you covered:

var future = new Date();
future.setDate(future.getDate() + 30);

That'll just do the right thing. (It's a little confusing that the getter/setters for day-of-month have the names they do.)

like image 162
Pointy Avatar answered Nov 11 '22 13:11

Pointy