How to calculate date 30 days from today

I need to calculate the date from thirty days using Dateinjavascript

var now = new Date();

Example:

if today is February 13, 2013, 30 days later - March 15, 2013, so something that is different from 30DaysLaterMonth = ActualMonth+1.

I hope my question is clear .. :) thanks to everyone!

+3
source share
5 answers

I think you better use Datejs

Datejs is an open source JavaScript date library.

or you can do it yourself:

var cur = new Date(),
    after30days = cur.setDate(cur.getDate() + 30);
+6
source
var now = new Date(); 
now.setDate(now.getDate() + 30);
+4
source
var now = new Date();
var 30DaysLaterMonth = now.getDate() + 30;
+3
source

In native javascript, use Date.UTC(year, month, day)to get the number of milliseconds since 1971-01-01. Then add the days * (86400000) and create a date from this value:

var date_one_ms = Date.UTC(2012, 05, 25);
var ms_in_day = 24*3600*1000; // 86400000;
var date_30_days_later = new Date(date_one_ms + 30 * ms_in_day);
0
source
var d = new Date();
   d.setDate(d.getDate() + 30);
0
source

All Articles