|  |  | 
 |  |  | import java.text.DateFormatSymbols; | 
 |  |  | import java.text.ParseException; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.ZoneId; | 
 |  |  | import java.time.ZonedDateTime; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     public DateUtil() { | 
 |  |  |     } | 
 |  |  |     public static Date getDateFromLocalDateTime(  LocalDateTime localDateTime) { | 
 |  |  |         try { | 
 |  |  |             ZoneId zoneId = ZoneId.systemDefault(); // 获取系统默认时区 | 
 |  |  |             ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); // 转换为带时区的日期时间 | 
 |  |  |             Date date = Date.from(zonedDateTime.toInstant()); // 转换为Date | 
 |  |  |             return  date; | 
 |  |  |         }catch (Exception e){ | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         return null; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |     public static Date StringToDate2(String DATE) { | 
 |  |  |         if(StringUtils.isBlank(DATE)){ | 
 |  |  |             return null; | 
 |  |  | 
 |  |  |             exception.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         return dt1; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public static Date StringToDateFormat(String DATE,String format) { | 
 |  |  |         if(StringUtils.isBlank(DATE)){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         DateFormat df = new SimpleDateFormat(format); | 
 |  |  |         Date dt1 = null; | 
 |  |  |         try { | 
 |  |  |             dt1 = df.parse(DATE); | 
 |  |  |         } catch (Exception exception) { | 
 |  |  |             exception.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         return dt1; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public static String getXDaysAfter(Date date, Integer days){ | 
 |  |  |         Timestamp currentTimestamp = new Timestamp(date.getTime()); | 
 |  |  |         Calendar calendar = Calendar.getInstance(); | 
 |  |  |         calendar.setTime(currentTimestamp); | 
 |  |  |         calendar.add(Calendar.DAY_OF_YEAR, days); // 在当前时间基础上添加指定的天数 | 
 |  |  |         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |         return formatter.format(calendar.getTime()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 得出两个日期之间的间隔天数 | 
 |  |  |      * | 
 |  |  |      * @param strFromDate | 
 |  |  |      * @param smallDate | 
 |  |  |      *            格式为yyyy-MM-dd | 
 |  |  |      * @param strToDate | 
 |  |  |      * @param bigDate | 
 |  |  |      *            格式为yyyy-MM-dd | 
 |  |  |      * @return int | 
 |  |  |      */ | 
 |  |  |     public static long getBetweenDays(String strFromDate, String strToDate) { | 
 |  |  |     public static long getBetweenDays(String smallDate, String bigDate) { | 
 |  |  |         long m_intervalday = 0;// 初始化时间间隔的值为0 | 
 |  |  |         // 使用的时间格式为yyyy-MM-dd | 
 |  |  |         SimpleDateFormat m_simpledateformat = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |         try { | 
 |  |  |             Date fromDate = m_simpledateformat.parse(strFromDate); | 
 |  |  |             Date toDate = m_simpledateformat.parse(strToDate); | 
 |  |  |             Date fromDate = m_simpledateformat.parse(smallDate); | 
 |  |  |             Date toDate = m_simpledateformat.parse(bigDate); | 
 |  |  |             m_intervalday = toDate.getTime() - fromDate.getTime();// 计算所得为微秒数 | 
 |  |  |             m_intervalday = m_intervalday / 1000 / 60 / 60 / 24;// 计算所得的天数 | 
 |  |  |  | 
 |  |  | 
 |  |  |     } | 
 |  |  |     public static Date getDateFromString2(String strDate) { | 
 |  |  |         if (StringUtils.isEmpty(strDate)) { | 
 |  |  |             return new Date(System.currentTimeMillis()); | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         try { | 
 |  |  |             return sdfLongTimePlus.parse(strDate); | 
 |  |  | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) { | 
 |  |  |         try { | 
 |  |  |             System.out.println(RandomStringUtils.randomNumeric(3)); | 
 |  |  |             System.out.println(DateUtil.getCurrDate()); | 
 |  |  |         } catch (Exception ex) { | 
 |  |  |             ex.printStackTrace(); | 
 |  |  |         } | 
 |  |  | 
 |  |  |         return (int)diff + 1 ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static Integer between(Date begin, Date end) { | 
 |  |  |         if(begin ==null ){ | 
 |  |  |             return  0; | 
 |  |  |         } | 
 |  |  |         long createTime =begin.getTime();//获取创建时间的时间戳 | 
 |  |  |         long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//获取当前时间的时间戳 | 
 |  |  |         long diff=(currentTime-createTime)/1000/60;//获取两个时间相差的分钟 | 
 |  |  |         return (int)diff; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static Integer betweenSeconds(Date begin, Date end) { | 
 |  |  |         if(begin ==null ){ | 
 |  |  |             return  0; | 
 |  |  |         } | 
 |  |  |         long createTime =begin.getTime();//获取创建时间的时间戳 | 
 |  |  |         long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//获取当前时间的时间戳 | 
 |  |  |         long diff=(currentTime-createTime)/1000;//获取两个时间相差的分钟 | 
 |  |  |         return (int)diff; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 计算耗时 |