How to get number of days between two calendar instance?

后端 未结 11 1124
孤城傲影
孤城傲影 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
    慢半拍i (楼主)
    2020-12-05 02:57

    Try the following approach:

    public static long daysBetween(Calendar startDate, Calendar endDate) {
        long end = endDate.getTimeInMillis();
        long start = startDate.getTimeInMillis();
        return TimeUnit.MILLISECONDS.toDays(Math.abs(end - start));
    }
    

提交回复
热议问题