How to get number of days between two calendar instance?

后端 未结 11 1125
孤城傲影
孤城傲影 2020-12-05 01:58

I want to find the difference between two Calendar objects in number of days if there is date change like If clock ticked from 23:59-0:00 there should be a day

11条回答
  •  旧时难觅i
    2020-12-05 02:40

    In Java 8 and later, we could simply use the java.time classes.

    hoursBetween = ChronoUnit.HOURS.between(calendarObj.toInstant(), calendarObj.toInstant());
    
    daysBetween = ChronoUnit.DAYS.between(calendarObj.toInstant(), calendarObj.toInstant());
    

提交回复
热议问题