Android/Java - Date Difference in days

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

    Most of the answers were good and right for your problem of

    so i want to find the difference between date in number of days, how do i find difference in days?

    I suggest this very simple and straightforward approach that is guaranteed to give you the correct difference in any time zone:

    int difference= 
    ((int)((startDate.getTime()/(24*60*60*1000))
    -(int)(endDate.getTime()/(24*60*60*1000))));
    

    And that's it!

提交回复
热议问题