SoFunction
Updated on 2025-04-07

Time zone issues with Javascript date processing


//dateObj is a date object. Days indicates how many days to add to this date, such as 4 or 5 (days)
function dateAdd(dateObj,days){
var tempDate = ();
tempDate = tempDate + days * 24 * 60 * 60 * 1000;
tempDate = new Date(tempDate);
return tempDate;
}

// Then use, create a date object
var dateValue = ("XXYY").("-");
var custArvDateTwoValue = new Date(dateValue[0],dateValue[1]-1,dateValue[2]);
//Call dateAdd, add two days
custArvDateTwoValue = dateAdd(custArvDateTwoValue,2);
var year = ();
var month = () + 1;
var days = ();
month = month <= 9 ? "0"+month : month;
days = days <= 9 ? "0"+days : days;
("XX").value = year + "-" + month + "-" +days;