I have following method that I would like to make shorter or faster if nothing else. Please all comments are welcome:
Bellow method takes a date object, formates i
Another way of comparing dates apart from the accepted answer above using java.util.Date.getTime() (note: long should be used instead of int):
Date today=new Date();
Date dateObj=null;
long diff=0;
try{
dateObj= formater1.parse(date);
diff=(today.getTime()-dateObj.getTime())/(86400000);
}catch(Exception e){}
String days="TODAY";
if(diff==1){
days = "YESTERDAY";
}else if(diff>1){
days = String.valueOf(diff) + " " +"DAYS AGO";
}
<%=days%> would return:
TODAY
YESTERDAY
x DAYS AGO