i am trying to compare two dates using "after" method in android. here is my two dates
currentDate :Fri Sep 12 00:00:00 GMT+05:30 2014
expDate :Tue Sep 01 00:00:00 GMT+05:30 2015
my code is as follows
private boolean checkDate(String date) throws ParseException{
Calendar c = Calendar.getInstance();
String cYear = String.valueOf(c.get(Calendar.YEAR)).substring(0, 2);
String digit1 = date.substring(2,4);
String digit2 = date.substring(0, 2);
String finalDate = cYear+digit1+"-"+digit2+"-"+"01";
SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd");
Date expDate = curFormater.parse(finalDate);
String cDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
Date curentDate = curFormater.parse(cDate);
if(curentDate.after(expDate)){
return true;
}else{
return false;
}
}
but my if condition is always returns false. i don't know whats wrong with the code. please some one help me about this..
thank you.
0 comments:
Post a Comment