How to find difference two dates on android app
android, date
Solution
SimpleDateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date d = null;
java.util.Date d1 = null;
Calendar cal = Calendar.getInstance();
try {
d = dfDate.parse("01/02/2012 ");
d1 = dfDate.parse(dfDate.format(cal.getTime()));//Returns 15/10/2012
} catch (java.text.ParseException e) {
e.printStackTrace();
}
int diffInDays = (int) ((d.getTime() - d1.getTime())/ (1000 * 60 * 60 * 24));
System.out.println(diffInDays);
Check Ex1 and Ex2 for more detailed example
Problem
Possible Duplicate: Calculate date/time difference in java I am a new on Android and I want to make a new app for me. I want to subtruct two dates (dd/mm/yyyy) format by using currentDate. For example I want to find the differences of the days between 01/02/2013 and currentDate. How can I do it?