yujian
2019-08-09 41aec48fb1e43f42807b1c71c9aeb19ebbf7506c
utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -192,16 +192,31 @@
    * @return 相差天数
    * @throws ParseException calendar 对日期进行时间操作 getTimeInMillis() 获取日期的毫秒显示形式
    */
   public static int daysBetween(Date smdate, Date bdate) throws ParseException {
   public static int daysBetween(Date minDate, Date maxDate) throws ParseException {
      Calendar cal = Calendar.getInstance();
      cal.setTime(smdate);
      long time1 = cal.getTimeInMillis();
      cal.setTime(bdate);
      long time2 = cal.getTimeInMillis();
      long between_days = (time2 - time1) / (1000 * 3600 * 24);
      cal.setTime(minDate);
      long minTime = cal.getTimeInMillis();
      cal.setTime(maxDate);
      long maxTime = cal.getTimeInMillis();
      long between_days = (maxTime - minTime) / (1000 * 3600 * 24);
      return Integer.parseInt(String.valueOf(between_days));
   }
   /**
    * 字符串日期格式的计算
    *
    * @param smdate
    * @param bdate
    * @return  单位天数
    * @throws ParseException
    */
   public static int daysBetween2(Date minDate, Date maxDate) throws ParseException {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      return daysBetween(sdf.format(minDate), sdf.format(maxDate));
   }
   /**
    * 字符串日期格式的计算
    * 
@@ -210,14 +225,14 @@
    * @return
    * @throws ParseException
    */
   public static int daysBetween(String smdate, String bdate) throws ParseException {
   public static int daysBetween(String minDate, String maxDate) throws ParseException {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      Calendar cal = Calendar.getInstance();
      cal.setTime(sdf.parse(smdate));
      long time1 = cal.getTimeInMillis();
      cal.setTime(sdf.parse(bdate));
      long time2 = cal.getTimeInMillis();
      long between_days = (time2 - time1) / (1000 * 3600 * 24);
      cal.setTime(sdf.parse(minDate));
      long minTime = cal.getTimeInMillis();
      cal.setTime(sdf.parse(maxDate));
      long maxTime = cal.getTimeInMillis();
      long between_days = (maxTime - minTime) / (1000 * 3600 * 24);
      return Integer.parseInt(String.valueOf(between_days));
   }
@@ -253,10 +268,11 @@
   /**
    * 随机减去几分钟
    * @param date
    * @param min 随机添加的分钟数
    * @return
    */
   public static Date reduceRandomMinute(Date date) {
      long rand = (long) (Math.random() * 60 * 8);
   public static Date reduceRandomMinute(Date date , int min) {
      long rand = (long) (Math.random() * 1000 * 60 * min);
      long time = date.getTime() - rand;
      return new Date(time);
   }