按指定天数计算日期
Calculate the date by the specified number of days
我使用 Android Studio。我想从我指定的日期计算280天后的那一天。
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));
日志输出变量。有时285283279种
简单cal.add(Calendar.DATE, 280);
LocalDate myDate = LocalDate.now();
LocalDate datePlusDays = myDate.plusDays(280);
System.out.println("Today Plus 280 Days: " + datePlusDays);
我使用 Android Studio。我想从我指定的日期计算280天后的那一天。
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));
日志输出变量。有时285283279种
简单cal.add(Calendar.DATE, 280);
LocalDate myDate = LocalDate.now();
LocalDate datePlusDays = myDate.plusDays(280);
System.out.println("Today Plus 280 Days: " + datePlusDays);