public static String getDate(String dateGiven,Integer day) throws Exception{ SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); Date date=sdf.parse(dateGiven); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE,day);//把日期日后增长一天.整数日后推,负数往前移动 date=calendar.getTime(); //这个时间就是日期日后推一天的结果 String dateString = formatter.format(date); return dateString; }----------------------------------------------华丽的分割线------------------------------------------------spa
// 如下整理来自 “加菲爱” 点提基于Java8的实用方法 // 当前系统日期 LocalDateTime now = LocalDateTime.now(); System.out.println("当前系统时间为:" + now); // 一天后的日期 System.out.println("一天后的日期为:" + now.plusDays(1L)); // 一天前的日期 System.out.println("一天前的日期为:" + now.minusDays(1L)); // LocalDateTime 格式化时间 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formatNow = dtf.format(now); System.out.println("格式化当前系统时间为:" + formatNow);