比如現在有個String str =”2015-07-18”;
現在要在這個時間上加8個月就變成了“2016-03-18”
怎麼完成這種時間的轉換加減
String str = "2015-07-18";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
Date myDate = formatter.parse(str);
Calendar c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.MONTH, 8);
myDate = c.getTime();
System.out.println(formatter.format(myDate));
} catch (ParseException e1) {
e1.printStackTrace();
}
*