如何在Java中计算日期
我是java的初学者。我需要计算一下日期。如果我输入持续时间并选择开始日期,则应自动计算结束日期。我已经在jQuery中完成了这项工作,它很有效
这是我在jQuery中尝试的工作代码:
$( "#start_date" ).change(function() {
if($( "#duration" ).val()==""){
return false;
}
var x = Number($( "#duration" ).val());
var CurrentDate = new Date($("#start_date" ).val());
CurrentDate.setMonth(CurrentDate.getMonth() + x);
$("#end_date" ).val(CurrentDate.toISOString().split('T')[0]);
});
要选择我使用jDateChooser的日期,请执行以下操作:
int duration = Integer.parseInt(txtdur.getText());
Date date = new Date();
SimpleDateFormat Date_Format = new SimpleDateFormat("yyyy-MM-dd");
String date1 = Date_Format.format(txtdate.getDate());
之后我不知道代码有多完整
# 1 楼答案
您应该将日期转换为即时,并添加所需的时间