How to find the number of days between two dates in java or groovy?

后端 未结 9 1791
走了就别回头了
走了就别回头了 2020-12-09 19:25

I have a method which uses following logic to calculate difference between days.

long diff = milliseconds2 - milliseconds1;
long diffDays = diff / (24 * 60 *         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 20:21

    This assumes times are in UTC or GMT.

    long day1 = milliseconds1/ (24 * 60 * 60 * 1000);
    long day2 = milliseconds2/ (24 * 60 * 60 * 1000);
    // the difference plus one to be inclusive of all days
    long intervalDays = day2 - day1 + 1; 
    

提交回复
热议问题