public static void main(String[] args) {
String date1 = "2017-07-30";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
Date d1 = df.parse(date1);
System.out.println("d1=="+df.format(d1));
Calendar g = Calendar.getInstance();
g.setTime(d1);
g.add(Calendar.YEAR,-1);//年份减1
g.add(Calendar.MONTH,-1);//月份减1
Date d2 = g.getTime();
System.out.println("d2======="+df.format(d2));
} catch (ParseException e) {
e.printStackTrace();
}
}
String date1 = "2017-07-30";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
Date d1 = df.parse(date1);
System.out.println("d1=="+df.format(d1));
Calendar g = Calendar.getInstance();
g.setTime(d1);
g.add(Calendar.YEAR,-1);//年份减1
g.add(Calendar.MONTH,-1);//月份减1
Date d2 = g.getTime();
System.out.println("d2======="+df.format(d2));
} catch (ParseException e) {
e.printStackTrace();
}
}