JS代码:
jsp页面代码
<script language="JavaScript">
function adddays(form) {
var DaysToAdd=document.form.dayadd.value;
var now=new Date();
var newdate=new Date();
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
//只得到年月日的
alert(newdate.getFullYear()+"-"+(newdate.getMonth()+1)+"-"+newdate.getDate());
//得到具体时间
document.form.display.value=newdate.toLocaleString();
}
</script>
jsp页面代码
<form name=form>
<input type=text name="dayadd" size=4 value=10 onFocus="this.select()" onMouseOver="this.focus()">
<input type=button value="天后的日期是:" onClick="adddays(this.form)" name="button">
<input type=text name="display" size=20 value="">
</form>