Copy Code code as follows:
Dateobj is a Date object, days indicate to this date add how many day, for example 4,5 (days)
function DateAdd (dateobj,days) {
var tempdate = dateobj.valueof ();
Tempdate = tempdate + days * 24 * 60 * 60 * 1000;
Tempdate = new Date (tempdate);
return tempdate;
}
Then use, create a Date object
var dateValue = document.getElementById ("XXYY"). Value.split ("-");
var custarvdatetwovalue = new Date (datevalue[0],datevalue[1]-1,datevalue[2]);
Call DateAdd, add two days
Custarvdatetwovalue = DateAdd (custarvdatetwovalue,2);
var year = Custarvdatetwovalue.getfullyear ();
var month = Custarvdatetwovalue.getmonth () + 1;
var days = Custarvdatetwovalue.getdate ();
Month = Month <= 9? "0" +month:month;
Days = Days <= 9? "0" +days:days;
document.getElementById ("XX"). Value = year + "-" + month + "-" +days;
When I was testing, I found that when document.getElementById ("XXYY"). Value is 2009-10-31
The return was incredibly 2009-11-01.
All other things being right, like entering 2009-10-01, returning to 2009-10-03
I also tried today and next year the last day of the month, only 2009-10-31 problem (I tried a lot of time, only this time has a problem, the difficulty of this month has 32 days)
When I try 2009-10-31, it's also true that 2009-11-01 is back.
Finally found that the time zone is the problem, so we later found such a problem, you can see if the time zone is not the corresponding.