import java.text.DateFormat;
import java.util.Date;
public class DatePlus {
public static void main(String[] args) {
Date now = new Date();
//Date now1 = new Date();
Date now2 = new Date();
DateFormat currentDate = DateFormat.getDateInstance();
int count1=10;
int count2=15;
Date addedDate1 = addDays(now2, count1);
Date addedDate2 = addDays(addedDate1, count2);
System.out.println(currentDate.format(addedDate1));
System.out.println(currentDate.format(addedDate2));
}
public static Date addDays(Date d, int days) {
d.setTime(d.getTime() + days * 1000 * 60 * 60 * 24);
return d;
}
}
尽管预期输出不同,但日期addedDate1
和输出语句都打印相同的日期。addedDate2