Java 计算日期加、减一天

public static void main(String[] args)
       throws ParseException
   {
       SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd");
       String today = "2015-11-30";
       Date d = sj.parse(today);
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(d);
       calendar.add(Calendar.DATE, 1);
       System.out.println("明天:" +      sj.format(calendar.getTime()));
       //此时日期变为2015-12-01 ,所以下面的-2,
       //理论上讲应该是2015-11-29
       calendar.add(calendar.DATE, -2);
       System.out.println("前天:" + sj.format(calendar.getTime()));
   }

你可能感兴趣的:(Java 计算日期加、减一天)