Time zone for processing Javascript date _ time and date

Source: Internet
Author: User
So if you find this type of problem in the future, you can check whether the time zone does not match. The Code is as follows:


// DateObj is a date object. days indicates how many days are added to the date, for example, 4 or 5 days)
Function dateAdd (dateObj, days ){
Var tempDate = dateObj. valueOf ();
TempDate = tempDate + days * 24*60*60*1000;
TempDate = new Date (tempDate );
Return tempDate;
}

// Create a date object.
Var dateValue = document. getElementById ("XXYY"). value. split ("-");
Var custArvDateTwoValue = new Date (dateValue [0], dateValue [1]-1, dateValue [2]);
// Call dateAdd and 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;


During the test, I found that when document. getElementById ("XXYY"). value is
The returned result is.

All other situations are correct. For example, enter 2009-10-01 and return 2009-1003.
I also tried today and next year's last day of each month, and there was only a problem in (I tried a lot of time, only this time there was a problem, the difficulty of this month has 32 days)

When I try, the returned result is.

At last, we found that it was a problem with the time zone, so we will find this problem in the future. You can check whether the time zone does not match.

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.