We have to do some security check for which we are getting some date from some part of our code and then we are calculating the difference in days
String userDate = EncryptUtil.getInstance().decrypt(Constants.USER_DATE);
String currentDate = new SimpleDateFormat("dd/MM/yyyy").format(calendar.getTime());
long startTime = new Date(userDate).getTime();
long presentTime = new Date(currentDate).getTime();
long diffTime = presentTime - startTime;
long diffDays = diffTime / (1000 * 60 * 60 * 24);
The userDate
value is coming 03/06/2017
and currentDate
is 07/06/2017
, both are correct, but when I'm calculating day difference (diffDays
) it is giving a difference of 122, where it should be actually 4. I don't understand why? Can anybody help.