Possible Duplicate:
Compare dates in java
I am getting two dates from server in yyyy-MM-dd format. I have to compare between these two dates. I used compareTo() method to compare two dates. what is more easier way to compare two dates assuming my server will always return not null value in yyyy-MM-dd format?
Define the method
void compareTwoDates(String startDate, String endDate){
switch(startDate.compareTo(endDate)){
case -1:
//START DATE IS BIGGER THAN END DATE
System.out.println(endDate+" IS BIGGER THAN "+startDate);
break;
case 0:
//BOTH DATE ARE SAME
System.out.println("SAME DATE");
break;
case 1:
//END DATE IS BIGGER
System.out.println(startDate+" IS BIGGER THAN "+endDate);
break;
}
}
call the method using following way
compareTwoDates("2012-05-06", "2012-04-08");
compareTwoDates("2012-04-09", "2012-04-09");
compareTwoDates("2012-04-09", "2011-05-10");