Number of days between two dates in Joda-Time

后端 未结 8 1307
北恋
北恋 2020-11-22 09:07

How do I find the difference in Days between two Joda-Time DateTime instances? With ‘difference in days’ I mean if start is on Monday and end is on Tuesday I expect a return

8条回答
  •  孤独总比滥情好
    2020-11-22 09:59

    java.time.Period

    Use the java.time.Period class to count days.

    Since Java 8 calculating the difference is more intuitive using LocalDate, LocalDateTime to represent the two dates

        LocalDate now = LocalDate.now();
        LocalDate inputDate = LocalDate.of(2018, 11, 28);
    
        Period period = Period.between( inputDate, now);
        int diff = period.getDays();
        System.out.println("diff = " + diff);
    

提交回复
热议问题