After consulting a few forums, I ended up using the code below to find the days difference. But, I see a problem with the logic (may be it's my over sight?). I see that for days difference between 11 to 14 and 11 to 15 is same. How is it possible?
Date createdDate = new Date((2013 + 1900), (1 + 1), 11);
Date expirationDate = new Date((2013 + 1900), (1 + 1), 11);
for (int i = 11; i < 20; i++) {
expirationDate.setDate(i);
System.out.println("11 to " + i + " = "
+ (int) (expirationDate.getTime() - createdDate.getTime())
/ (1000 * 60 * 60 * 24));
}
The output is:
11 to 11 = 0
11 to 12 = 1
11 to 13 = 2
11 to 14 = 3
11 to 15 = 3
11 to 16 = 4
11 to 17 = 5
11 to 18 = 6
11 to 19 = 7