The problem is
Date createdDate = new Date();
sets createdDate at the current moment, that is, it includes the current time, as well as the date. When you parse a string using the specified format, the time is initialized to 00:00:00 .
Say you started it at exactly 18:00 local time, you ended up with
createdDate = 2016-06-27 18:00:00.000 expDate = 2016-06-30 00:00:00.000
The difference is 2 days 6 hours, not 3 days.
You should use the new java.time.* Classes from Java 8. There is a LocalDate class that represents dates without a time of day. It includes methods for parsing using the format and LocalDate.now() to get the current date, as well as methods for calculating the intervals between instances of LocalDate .
Jim garrison
source share