Sometime we need two compare two dates like which Date object's time coming first or last.
Here is the code to compare two dates.
Date date1;
Date date2;
if(date1.before(date2)){
System.out.println("Date 1 is before date 2");
}
if(date2.before(date1)){
System.out.println("Date 2 is before date 1");
}
if(date1.compareTo(date2)==0)
{
System.out.println("both dates are equals");
}
0 Comment(s)