Finding difference of days from start and end using joda?

This question already has an answer here:

  • Number of days between two dates in Joda-Time 6 answers

  • Use Days Class of Joda Library

    Days days=Days.daysBetween(startDate.toLocalDate(), endDate.toLocalDate()).getDays();
    int noOfDays=days.getDays();
    

    As an alternative we can also ues Java 8 Date and Time API

    public void days_between_two_dates_in_java_with_java8 () {
    
        LocalDate startDate = LocalDate.now().minusDays(1);
        LocalDate endDate = LocalDate.now();
    
        long days = Period.between(startDate, endDate).getDays();
    
    
        // or 
    
        long days2 = ChronoUnit.DAYS.between(startDate, endDate);
    
    }
    
    链接地址: http://www.djcxy.com/p/36658.html

    上一篇: 如何在Joda时间日期之间包含开始日期?

    下一篇: 使用joda从开始和结束找到天数差异?