-2

I use Android Studio. I want to calculate the day after 280 days from the date I specified.

Calendar thatDay = Calendar.getInstance(); //today date
thatDay.set(Calendar.DAY_OF_MONTH,selectedday);
thatDay.set(Calendar.MONTH,selectedmonth-1); // 0-11 so 1 less
thatDay.set(Calendar.YEAR, selectedyear);


Calendar afterday= Calendar.getInstance(); //280 after date
afterday.set(Calendar.DAY_OF_MONTH,selectedday+10);
afterday.set(Calendar.MONTH,selectedmonth+8); 
afterday.set(Calendar.YEAR, selectedyear);

Log.e(" After Day: ", " days:" +  (afterday.getTimeInMillis()- thatDay.getTimeInMillis())/ (24 * 60 * 60 * 1000));

log output variable. Sometimes 285,283,279 kind of

Emre Aydemir
  • 170
  • 2
  • 12

2 Answers2

2

Simply cal.add(Calendar.DATE, 280);

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
0
    LocalDate myDate = LocalDate.now();
    LocalDate datePlusDays = myDate.plusDays(280);
    System.out.println("Today Plus 280 Days: " + datePlusDays);
brijesh
  • 760
  • 6
  • 4