public int difftime(String string, String string2) {
int hours;
int min = 0;
int days;
long difference ;
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
Date date1 = simpleDateFormat.parse("08:00 AM");
Date date2 = simpleDateFormat.parse("04:00 PM");
difference = date2.getTime() - date1.getTime();
days = (int) (difference / (1000 * 60 * 60 * 24));
hours = (int) ((difference - (1000 * 60 * 60 * 24 * days)) / (1000 * 60 * 60));
min = (int) (difference - (1000 * 60 * 60 * 24 * days) - (1000 * 60 * 60 * hours))
/ (1000 * 60);
hours = (hours < 0 ? -hours : hours);
Log.i("======= Hours", " :: " + hours);
return min;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return min;
}
This is my function to get time difference in the form of minutes but it give always zero. I don't know where i did mistake please tell me where am doing mistake. I want result in the form of minutes.