简体   繁体   中英

How to find the next 4 days from the current day using javascript

I found the current day as Mar 27 2012 ....

var currentday = currentday.format("mmm d yyyy");

I want to find the add three days with this value.
ie i need the output as Mar 30 2012.

I also need to find the starting and ending date of a calendar. ie Feb 26 2012 - Mar 31 2012 to display the current month as displaying in calendar month view.

Can any one help me on this please....

var currentday = new Date();
var nextDay = new Date();
nextDay.setDate(currentday.getDate() + 4);
//Set number of days you want to compute to
var days=4;

//Get current date or whatever date you want to compute from
var currentDate=new Date();

var nDaysFromNow=new Date();
nDaysFromNow.setDate(currentDate.getDate()+days);

You can add days using the getDate() function like so:

var someDate = new Date();
someDate = someDate.getDate() + 3;

See code below.. Hope it helps

var days = 4;
var next = new Date((new Date).getTime() +  ((1000*3600*24) *days));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM