如何在java验证中编写日期验证的条件语句

如何在java验证中编写日期验证的条件语句,java,validation,Java,Validation,我正在使用Struts2处理java项目,其中currentDate是今天的日期,fromDate是用户输入的Date。fromDateDate应该与currentDate的日期相等或将来。我为将来的日期编写代码,如何写入条件fromDate应等于currentDate if(!(fromDate.after(currentDate))){ addFieldError("fromDate","The date is Older"); } fromDate日期应等于或晚于当前日期 如何写

我正在使用Struts2处理java项目,其中
currentDate
是今天的日期,
fromDate
是用户输入的
Date。fromDate
Date应该与
currentDate
的日期相等或将来。我为将来的日期编写代码,如何写入条件fromDate应等于currentDate

if(!(fromDate.after(currentDate))){
    addFieldError("fromDate","The date is Older");
}
fromDate日期应等于或晚于当前日期

如何写入条件fromDate<=CurrentDate

你上面写的两个陈述相互冲突。在你的措辞中,你说的是
fromDate>=currentDate
,但当你把
fromDate<=currentDate
放在
fromDate
之前或等于
currentDate>

根据您在下面的评论,您应该使用

 if(fromDate.before(currentDate)){
    addFieldError("fromDate","The from date should be future date");
 }

我在票证保留系统中使用此验证。在这种情况下,fromDate或toDate不应小于currentDate,因为在较早的日期中,我们将不保留票证。因此,fromDate日期应等于或晚于当前日期。@Sanket Dcheck now…更新了我的答案…您可以根据需要替换错误文本您的答案代码和我的代码得到了相同的答案。当我们在currentDate之前给出日期且fromDate=currentDate时,它会显示错误。但在我的条件声明中,我要求fromDate应与当前日期相等或更晚。