var dateTemp ="${requestScope.JBSJ}"
dateTemp = dateTemp.split("-")
//转换为MM-DD-YYYY格式
var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]) // Month 是你相加的月份个数
var newDate = dat.setMonth(dat.getMonth() + Month)
你看下是不是你想要的。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function checknow() {
var now = document.getElementById("now").value
var month= document.getElementById("month").value
if (month != "" && month.length > 0 && !isNaN(month))
{
var arr = now.split("-")
var y = parseInt(arr[0])
var m = parseInt(arr[1])
var d = parseInt(arr[2])
m += parseInt(month)
if (m > 12)
{
//y = parseInt(y + (m-12) / 12)
y = parseInt(y + m / 12)
m = m % 12
}
if (m == 2)
{
if (isPN(y,m,d))
{
d = 28
}
else {
d = 29
}
}
var newDate = y + "-" + m + "-" + d
alert(newDate)
}
}
function isPN(year,month,day) {
if (year % 100 == 0 && year % 400 == 0)
{
return true
}
if (year % 100 != 0 && year % 4 == 0)
{
return true
}
return false
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="text" NAME="now" id="now" value="2014-04-04">
<FORM METHOD=POST ACTION="">
<INPUT TYPE="text" NAME="month" id="month" onblur="checknow()">
</FORM>
</BODY>
</HTML>
调用Date对象setDate()函数,具体方法如下:function addDate(date,days){
var d=new Date(date)
d.setDate(d.getDate()+days)
var month=d.getMonth()+1
var day = d.getDate()
if(month<10){
month = "0"+month
}
if(day<10){
day = "0"+day
}
var val = d.getFullYear()+""+month+""+day
return val
}