Reputation: 4092
I am trying to calculate the difference between two dates but the function is not returning the value
I am calling the function like this
GeneralMethods generalMethods = new GeneralMethods();
generalMethods.daysPassed(contacts_update_date, currentDate);
And the function is as follows
public class GeneralMethods {
public long daysPassed(String contacts_update_date, String currentDate) {
// Calculate Time Passed
long diff;
long timePassed = 0;
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String inputString1 = contacts_update_date;
String inputString2 = currentDate;
try {
Date date1 = myFormat.parse(inputString1);
Date date2 = myFormat.parse(inputString2);
diff = date2.getTime() - date1.getTime();
timePassed = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
} catch (ParseException e) {
e.printStackTrace();
}
return timePassed;
}
}
Finally I am using the value like this
if (timePassed > 30) {
//do something
}
Upvotes: 1
Views: 102
Reputation: 994
Please try this
GeneralMethods generalMethods = new GeneralMethods();
long timePassed=generalMethods.daysPassed(contacts_update_date, currentDate);
Upvotes: 3