(Java / Android) Calculate days between 2 dates and present the result in a specific format

前端 未结 3 1534
离开以前
离开以前 2020-12-16 02:25

I am trying to do calculate days between 2 dates as follow:

  1. Obtain current date
  2. Obtain past OR future date
  3. Calculate the difference between n
3条回答
  •  [愿得一人]
    2020-12-16 02:55

    long delta = Date2.getTime() - Date1.getTime();
    
    new Date(delta);
    

    From here, you just pick your format. Maybe use a date formatter? As for determing the future stuff and all that, you could just see if the delta is positive or negative. A negative delta will indicate a past event.

提交回复
热议问题