代码如下
public class JavaApplication24 {
public static void main(String[] args) {
int year;
int month;
int day;
int num;
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
System.out.print("请输入年份:");
year=reader.nextInt();
System.out.print("请输入月份:");
month=reader.nextInt();
month=month-1;
System.out.print("请输入天数:");
day=reader.nextInt();
Date date=dateFormat.parse("year-month-day");
System.out.println("请输入所加天数:");
num=reader.nextInt();
Date addDate=addDate(num);
System.out.println("得到的新日期为:"+format.format(addDate));
}
public static Date addDate(int num)
{
Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.DATE,num);
Date date=calendar.getTime();
return date;
}
}
运行结果如下,这是为什么?