<html>
<body>
<script type="text/javascript">
//dateObj是一个日期对象,days表示给这个日期加多少天,比如说4,5(天)
function dateAdd(dateObj,days)
{
var tempDate = dateObj.valueOf();
tempDate = tempDate + days * 24 * 60 * 60 * 1000;
tempDate = new Date(tempDate);
return tempDate;
}
function changeDays(datevalues, days)
{
var datevalues = document.getElementById("startDate").value;
var days = document.getElementById("dayCount").value;
//然后使用,创建一个日期对象
var dateValue = datevalues.split("-");
var custArvDateTwoValue = new Date(dateValue[0],dateValue[1]-1,dateValue[2]);
//调用dateAdd,加两天
custArvDateTwoValue = dateAdd(custArvDateTwoValue,days);
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("endDate").value = year + "-" + month + "-" +days;
}
</script>
开始时间:<input type="text" id="startDate" value="2011-02-25"/><br/>
增加天数:<input type="text" id="dayCount" value="5"/><br/>
计算结果:<input type="text" id="endDate"/><br/>
<input type="button" onclick="changeDays()" value="计算"/>
</body>
</html>
<body>
<script type="text/javascript">
//dateObj是一个日期对象,days表示给这个日期加多少天,比如说4,5(天)
function dateAdd(dateObj,days)
{
var tempDate = dateObj.valueOf();
tempDate = tempDate + days * 24 * 60 * 60 * 1000;
tempDate = new Date(tempDate);
return tempDate;
}
function changeDays(datevalues, days)
{
var datevalues = document.getElementById("startDate").value;
var days = document.getElementById("dayCount").value;
//然后使用,创建一个日期对象
var dateValue = datevalues.split("-");
var custArvDateTwoValue = new Date(dateValue[0],dateValue[1]-1,dateValue[2]);
//调用dateAdd,加两天
custArvDateTwoValue = dateAdd(custArvDateTwoValue,days);
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("endDate").value = year + "-" + month + "-" +days;
}
</script>
开始时间:<input type="text" id="startDate" value="2011-02-25"/><br/>
增加天数:<input type="text" id="dayCount" value="5"/><br/>
计算结果:<input type="text" id="endDate"/><br/>
<input type="button" onclick="changeDays()" value="计算"/>
</body>
</html>