Calculating the number of days between two dates using joda time api

This question already has an answer here:

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

  • Use this

     Days.daysBetween(intdt.toLocalDate(), targetDt.toLocalDate()).getDays() 
    

    The LocalDate class does not store or represent a time or time-zone. Instead, it is a description of the date.


    SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
    String inputString1 = "23 01 1997";
    String inputString2 = "27 04 1997";
    
    try {
        Date date1 = myFormat.parse(inputString1);
        Date date2 = myFormat.parse(inputString2);
        long diff = date2.getTime() - date1.getTime();
        System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    
    链接地址: http://www.djcxy.com/p/36654.html

    上一篇: 如何比较Android应用中的日期?

    下一篇: 使用joda time api计算两个日期之间的天数