|  |  | 
 |  |  | import java.text.DateFormatSymbols; | 
 |  |  | import java.text.ParseException; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.ZoneId; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | 
 |  |  |         Date dt1 = null; | 
 |  |  |         try { | 
 |  |  |             dt1 = df.parse(DATE1); | 
 |  |  |         } catch (Exception exception) { | 
 |  |  |             exception.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         return dt1; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static Date StringToDateShort(String DATE) { | 
 |  |  |         DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |         Date dt1 = null; | 
 |  |  |         try { | 
 |  |  |             dt1 = df.parse(DATE); | 
 |  |  |         } catch (Exception exception) { | 
 |  |  |             exception.printStackTrace(); | 
 |  |  |         } | 
 |  |  | 
 |  |  |         cal.add(Calendar.MINUTE,minutes); | 
 |  |  |         return cal.getTime(); | 
 |  |  |     } | 
 |  |  | } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * LocalDateTime to date | 
 |  |  |      * @param now | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public static LocalDateTime toDateLocalDateTime(Date now){ | 
 |  |  |         return LocalDateTime.ofInstant(now.toInstant(), ZoneId.systemDefault()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * LocalDateTime to date | 
 |  |  |      * @param localDateTime | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public static Date toDate(LocalDateTime localDateTime){ | 
 |  |  |         Date from = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); | 
 |  |  |         return from; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static String afterDate(String date,int num){ | 
 |  |  |         Date today = DateUtil.StringToDateShort(date);   //当前时间 | 
 |  |  |         Calendar calendar = Calendar.getInstance(); //得到日历 | 
 |  |  |         calendar.setTime(today);//把当前时间赋给日历 | 
 |  |  |         calendar.add(Calendar.DAY_OF_MONTH, num);  //设置为前一天 | 
 |  |  |         Date yesterday = calendar.getTime();   //得到前一天的时间 | 
 |  |  |         calendar.setTime(today); | 
 |  |  |         calendar.add(Calendar.DAY_OF_MONTH, 1);  //设置为后一天 | 
 |  |  |         Date tomorrow = calendar.getTime(); | 
 |  |  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式 | 
 |  |  |         return sdf.format(calendar.getTime()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |