How to compare two dates along with time in java

后端 未结 6 1601
独厮守ぢ
独厮守ぢ 2020-11-29 07:30

I have two Date objects with the below format.

SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd\'T\'HH:mm:ss\");
String         


        
6条回答
  •  天涯浪人
    2020-11-29 08:03

    Use compareTo()

    Return Values

    0 if the argument Date is equal to this Date; a value less than 0 if this Date is before the Date argument; and a value greater than 0 if this Date is after the Date argument.

    Like

    if(date1.compareTo(date2)>0) 
    

提交回复
热议问题