I want to calculate the time difference.I have three EditTexts , I want to input the times in the first two edittexts in HH:MM format. And then calculate the time difference
Time Difference is calculated by following code:
long 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);
EDIT :
date1 and date2 are Date
objects, if you have EditText
then you can convert your text in to Date
object by using following code,
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // Make sure user insert date into edittext in this format.
Date dateObject;
try{
String dob=(tx.getText().toString());
dateObject = formatter.parse(dob);
date = new SimpleDateFormat("dd/MM/yyyy").format(dateObject);
}