如何在java验证中为Date验证编写Condition语句

时间:2017-04-26 06:08:58

标签: java validation

我正在使用Struts2处理java项目,其中currentDate是今天日期,而fromDate用户输入Date.fromDate日期应与{{1}相同或未来我编写了Future Date的代码,如何编写条件 fromDate应该等于currentDate

currentDate

1 个答案:

答案 0 :(得分:0)

  

fromDate date应与currentDate相等或未来。

     

如何编写条件fromDate< = CurrentDate。

上面写的两个陈述都是相互冲突的。在您的措辞中,您说的是fromDate>=currentDate但是当您提出fromDate < = CurrentDate时,您告诉fromDate应该在currentDate之前或之前,

根据您的评论,您应该使用

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