Android/Java - Date Difference in days

前端 未结 18 924
感动是毒
感动是毒 2020-11-22 14:17

I am getting the current date (in format 12/31/1999 i.e. mm/dd/yyyy) as using the below code:

Textview txtViewData;
txtViewDate.setText(\"Today is \" +
              


        
18条回答
  •  遇见更好的自我
    2020-11-22 14:35

    One another way:

    public static int numberOfDaysBetweenDates(Calendar fromDay, Calendar toDay) {
            fromDay = calendarStartOfDay(fromDay);
            toDay = calendarStartOfDay(toDay);
            long from = fromDay.getTimeInMillis();
            long to = toDay.getTimeInMillis();
            return (int) TimeUnit.MILLISECONDS.toDays(to - from);
        }
    

提交回复
热议问题