admin
2019-12-28 64a8f7a3be0a5584fe2164a2474b189c79cfab5c
utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -85,6 +85,34 @@
      dateInfo.setSecond(second);
      return dateInfo;
   }
   public static String dateDiff4(Date startTime, Date endTime) throws Exception {
      String datatime = "0分";
      long nm = 1000 * 60;// 一分钟的毫秒数
      long nh = 1000 * 60 * 60;// 一小时的毫秒数
      long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
      // 获得两个时间的毫秒时间差异
      long diff = endTime.getTime() - startTime.getTime();
      long day = diff / nd;// 计算差多少天
      long hour = diff % nd / nh;// 计算差多少小时
      long min = diff % nd % nh / nm;// 计算差多少分钟
      if (day > 0) {
         datatime = day + "天";
      } else {
         if (hour > 0) {
            datatime = hour + "时";
         } else {
            if (min < 0)
               min = 0;
            datatime = min + "分";
         }
      }
      return datatime;
   }
   /**
    * 通过时间秒毫秒数判断两个时间的间隔
@@ -422,6 +450,26 @@
        int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
      return Math.abs(month + result);
   }
   public static Date getTodayStartTime() {
      Calendar todayStart = Calendar.getInstance();
      todayStart.set(Calendar.HOUR_OF_DAY,0);
      todayStart.set(Calendar.MINUTE,0);
      todayStart.set(Calendar.SECOND,0);
      todayStart.set(Calendar.MILLISECOND,0);
      return todayStart.getTime();
   }
   public static Date getTodayEndTime() {
      Calendar todayEnd = Calendar.getInstance();
      todayEnd.set(Calendar.HOUR_OF_DAY,23);
      todayEnd.set(Calendar.MINUTE,59);
      todayEnd.set(Calendar.SECOND,59);
      todayEnd.set(Calendar.MILLISECOND,999);
      return todayEnd.getTime();
   }
   public static void main(String[] args) throws ParseException {
        System.out.println(getMonthSpace("2012-02", "2012-02"));