Android/Java - Date Difference in days

前端 未结 18 926
感动是毒
感动是毒 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:53

            Date userDob = new SimpleDateFormat("yyyy-MM-dd").parse(dob);
            Date today = new Date();
            long diff =  today.getTime() - userDob.getTime();
            int numOfDays = (int) (diff / (1000 * 60 * 60 * 24));
            int hours = (int) (diff / (1000 * 60 * 60));
            int minutes = (int) (diff / (1000 * 60));
            int seconds = (int) (diff / (1000));
    

提交回复
热议问题