Javascript Date Processing Time zone problem _ date

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.