Finding days difference in java

后端 未结 5 472
有刺的猬
有刺的猬 2021-01-15 18:53

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

5条回答
  •  隐瞒了意图╮
    2021-01-15 19:00

    Use Joda Time's Days#daysBetween(). There is no better way.

    DateMidnight createdDate = new DateMidnight(2013, 2, 11);
    
    for (int i = 11; i < 20; i++) {
    
        DateMidnight expirationDate = new DateMidnight(2013, 2, i);
        int dayDifference = Days.daysBetween(createdDate, expirationDate);
    
        System.out.println("11 to " + i + " = " + dayDifference);
    }
    

提交回复
热议问题