// calendar.roll(Calendar.DAY_OF_MONTH, 1);//加一天 import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class TestTime { public static void main(String[] args) { String d = "2004-1-1"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd");/*** 加一天*/ try { Date dd = df.parse(d); Calendar calendar = Calendar.getInstance(); calendar.setTime(dd); calendar.add(Calendar.DAY_OF_MONTH, 1);//加一天 System.out.println("增加一天之后:" + df.format(calendar.getTime())); } catch (ParseException e) { e.printStackTrace(); } /*** 减一天*/ try { long dif = df.parse(d).getTime()-86400*1000;//减一天 Date date=new Date();02 date.setTime(dif); System.out.println("减少一天之后:" + df.format(date)); } catch (ParseException e) { e.printStackTrace(); } } }