Home  >  Article  >  Web Front-end  >  Javascript date processing time zone issue_time and date

Javascript date processing time zone issue_time and date

WBOY
WBOYOriginal
2016-05-16 18:45:051040browse
Copy code The code is as follows:

//dateObj is a date object, days represents how much to add to this date Days, 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 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;

I found during testing that when the value of document.getElementById("XXYY").value is 2009-10-31
the returned value is actually 2009- 11-01

Other situations are correct, for example, if you enter 2009-10-01, it will return 2009-10-03
I also tried today and the last day of each month next year, only 2009 -10-31 has a problem (I tried many times, only this time has a problem, the difficulty is 32 days in this month)

When I try 2009-10-31, the returned is 2009-11-01 too Correct

In the end, it was found that it was a time zone problem, so if you find this kind of problem in the future, you can check to see if the time zone does not correspond.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn