开发环境 jdk 1.8
@Test public void testTime() throws ParseException { SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.DATE, -3); System.out.println(sj.format(calendar.getTime())); }
控制台打印如下