Javascript - Set date in 30 days

I need to set a date that will be in 30 days taking into account the months, which are 28,29,30,31 days, so it does not miss any days and shows exactly after 30 days. How can i do this?

+7
source share
5 answers

The JavaScript Date () object covers you:

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

It will be right. (It’s a little embarrassing that the recipient / setter for the day of the month has names that they make.)

+31
source

I wrote a date wrapper library that helps with parsing, manipulating, and formatting dates.

https://github.com/timrwood/moment

Here is how you could do it with Moment.js

var inThirtyDays = moment().add('days', 30);
+6

Date :

var future = new Date('Jan 1, 2014');

future.setTime(future.getTime() + 30 * 24 * 60 * 60 * 1000); // Jan 31, 2014

Date functions setTime and getTime use milliseconds since January 1, 1970 ( link ).

+5
source
var now = new Date();
var THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
var thirtyDaysFromNow = now + THIRTY_DAYS;
+4
source

Try this piece of code:

const date = new Date();
futureDate = new Date(date.setDate(date.getDate() + 30)).toLocaleDateString();
0
source

All Articles