var $date = $('#field').val();
date = get_date_from_string($date);
alert(date); //Sun Feb 10 2013 00:00:00 GMT+0100 (CET)
如何添加到date
四天?
答案 0 :(得分:1)
试试这个
var today= new Date();
today.setDate(today.getDate() + 4);
答案 1 :(得分:0)
使用以下功能
var $date = $('#field').val();
newdate = addDays1($date,4)
alert(newdate);
function addDays1(date1,days)
{
var date = date1;
var d = date.substring(0,2);
var m = date.substring(3,5);
var y = date.substring(6,10);
var tdays=parseFloat(d)+parseInt(days);
while(tdays!=0)
{
var dmax = caldays(m,y);
if(dmax>=tdays)
{
var day = tdays;
tdays =0;
}
else
{
var day =parseInt(tdays)-parseInt(dmax);
var tdays= day;
var Month = ((m*10)/10)+1;
var dmax = caldays(Month,y);
if(Month>12)
{
m =parseInt(Month)-12;
day = days;
y = parseInt(y)+1;
if(days<dmax)
tdays=0;
}
else
m =parseInt(Month);
y = parseInt(y);
day = tdays;
if(day<=dmax)
tdays=0;
}
}
if(tdays==0)
{
if(day<10)
{
day="0"+day;
}
if(m<10)
{
m=(m*10)/10;
m="0"+m;
}
var str=day+"/"+m+"/"+y;
return str;
}
}
答案 2 :(得分:0)
请尝试使用此代码。
var today = new Date();
var newDay = new Date(today.setDate(today.getDate()+4));