いくつかのフォーラムを調べた後、私は日数の違いを見つけるために以下のコードを使用することになりました。しかし、ロジックに問題があります(私の見落としかもしれません)。11から14と11から15の日数の差は同じであることがわかります。どうしてそれは可能ですか?
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));
}
出力は次のとおりです。
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