//日历对象
Calendar calendar = Calendar.getInstance();
//当前系统时间加2天
calendar.add(Calendar.DATE, 2);
Date date = calendar.getTime();
我还写了一种在jsp页面点击时获取当前时间的,同时ajax与jquery传值
function onclick1(c) {
alert("点击删除onclick事件");
/*
*一点击删除就获取时间,判断交给controller
*/
var date = new Date();
var s1 = "-";
var s2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var d = date.getFullYear() + s1 + month + s1 + strDate
+ " " + date.getHours() + s2 + date.getMinutes()
+ s2 + date.getSeconds();
/*
*与此同时触发ajax函数,获得delete_date
*/
var delete_date = d;
var customer_cd = c;
$.ajax({
url: "<%=basePath%>/queryAllywy.do?method=updateDelete",
type:"post",
async:false,
traditional:true,
contentType:"application/x-www-form-urlencoded;charset=utf-8",
data: {
delete_date : delete_date,
customer_cd : customer_cd
},
dataType:"json",
//成功执行操作,【error:】失败执行操作
success:function(data) {
if (data == 1) {
alert('请求已提交');
location.replace("<%=basePath%>queryAllywy.do?method=queryAll");
} else {
alert('请求错误return!=1');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//ajax请求失败后触发的方法
alert('出现错误无法提交');//弹出错误信息
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
},
})
};