你看下是不是你想要的。
<!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>
var day = document.getElementById("YQYS").valuevar 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)
function DateAdd(interval,number,date){
/*
* 功能:实现VBScript的DateAdd功能.
* 参数:interval,字符串表达式,表示要添加的时间间隔.
* 参数:number,数值表达式,表示要添加的时间间隔的个数.
* 参数:date,时间对象.
* 返回:新的时间对象.
* var now = new Date()
* var newDate = DateAdd( "d ",5,now)
*--------------- DateAdd(interval,number,date) -----------------
*/
switch(interval)
{
case "y " : {
date.setFullYear(date.getFullYear()+number)
return date
break
}
case "q " : {
date.setMonth(date.getMonth()+number*3)
return date
break
}
case "m " : {
date.setMonth(date.getMonth()+number)
return date
break
}
case "w " : {
date.setDate(date.getDate()+number*7)
return date
break
}
case "d " : {
date.setDate(date.getDate()+number)
return date
break
}
case "h " : {
date.setHours(date.getHours()+number)
return date
break
}
case "m " : {
date.setMinutes(date.getMinutes()+number)
return date
break
}
case "s " : {
date.setSeconds(date.getSeconds()+number)
return date
break
}
default : {
date.setDate(d.getDate()+number)
return date
break
}
}
}
var now = new Date()
//加五天.
var newDate = DateAdd( "d ",5,now)
alert(newDate.toLocaleDateString())
//加两个月.
newDate = DateAdd( "m ",2,now)
alert(newDate.toLocaleDateString())
//加一年
newDate = DateAdd( "y ",1,now)
alert(newDate.toLocaleDateString())