问题很简单,如何在YYYY-MM-DD格式的日期中添加天数?
例如,将日期"2013-02-11"增加一天变为"2013-02-12"?
例如,将日期"2013-02-11"增加一天变为"2013-02-12"?
date = new Date('2013-02-11');
next_date = new Date(date.setDate(date.getDate() + 1));
here's a demo http://jsfiddle.net/MEptb/
类似这样:
var date = new Date('2013-02-11');
/* Add nr of days*/
date.setDate(date.getDate() + 1);
alert(date.toString());
希望以下代码对您有所帮助
function addDays(myDate,days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}
var myDate = new Date('2013-02-11');
var newDate = addDays(myDate,5);
使用日期参数,您可以添加所需的日期,并使用addDays()
函数添加天数:
var start_date = new Date('2013-02-11');
var next_date_update = addDays(start_date,1);
var next_date = new Date(next_date_update).toLocaleDateString('en-CA');
if(next_date!='Invalid Date')
{
var final_date = next_date;
console.log(final_date);
}
function addDays ( myDate , days)
{
return new Date(myDate.getTime() + days*24*60*60*1000);
}
希望能对你有所帮助
function addDaysToCurrentDate(noofDays){
date = new Date();
next_date = new Date(date.setDate(date.getDate() + noofDays));
var IncrementedDate = next_date.toISOString().slice(0, 10);
console.log("Incremented Date " +IncrementedDate );
return IncrementedDate;
}
'2013-02-11'
,你想增加天数字段的值吗? - Felix Klingnew Date().toISOString().slice(0,10);
- Paul S.