yujian
2020-05-12 fb885c8bff26484f2bb21e697f182cc35bc4fa63
utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -139,7 +139,6 @@
      return datatime;
   }
   
   public static long dateDiffMin(Date startTime, Date endTime) throws Exception {
      long nm = 1000 * 60;// 一分钟的毫秒数
      long nh = 1000 * 60 * 60;// 一小时的毫秒数
@@ -152,8 +151,6 @@
      long min = diff % nd % nh / nm  + day * 24 * 60 + hour * 60;// 计算差多少分钟
      return min;
   }
   
   /**
    * 通过时间秒毫秒数判断两个时间的间隔
@@ -282,7 +279,6 @@
      return format.format(ca.getTime());
   }
   /**
    * 指定日期加上天数后的日期
    * 
@@ -300,6 +296,7 @@
   
   /**
    * 加上月份
    *
    * @param currdate
    * @param num
    * @return
@@ -313,6 +310,7 @@
   
   /**
    * 加上年份
    *
    * @param currdate
    * @param num
    * @return
@@ -324,6 +322,19 @@
      return ca.getTime();
   }
   /**
    * 减去月份
    *
    * @param currdate
    * @param num
    * @return
    */
   public static Date reduceMonth(Date currdate, int num) {
      Calendar ca = Calendar.getInstance();
      ca.setTime(currdate);
      ca.add(Calendar.MONTH, -num);
      return ca.getTime();
   }
   
   /**
    * 指定日期减去天数后的日期
@@ -532,7 +543,6 @@
      return Math.abs(month + result);
   }
   
   public static Date getTodayStartTime() {
      Calendar todayStart = Calendar.getInstance();
      todayStart.set(Calendar.HOUR_OF_DAY,0);
@@ -551,6 +561,73 @@
      return todayEnd.getTime();
   }
   
   /**
    * 获取指定年月的第一天
    *
    * @param yearMonth
    * @return
    */
   public static String getFirstDayOfMonth(String yearMonth) {
      int year = Integer.parseInt(yearMonth.split("-")[0]); // 年
      int month = Integer.parseInt(yearMonth.split("-")[1]); // 月
      return getFirstDayOfMonth(year, month);
   }
   /**
    * 获取指定年月的第一天
    *
    * @param year
    * @param month
    * @return
    */
   public static String getFirstDayOfMonth(int year, int month) {
      Calendar cal = Calendar.getInstance();
      // 设置年份
      cal.set(Calendar.YEAR, year);
      // 设置月份
      cal.set(Calendar.MONTH, month - 1);
      // 获取某月最小天数
      int firstDay = cal.getMinimum(Calendar.DATE);
      // 设置日历中月份的最小天数
      cal.set(Calendar.DAY_OF_MONTH, firstDay);
      // 格式化日期
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      return sdf.format(cal.getTime());
   }
   /**
    * 获取指定年月的最后一天
    *
    * @param yearMonth
    * @return
    */
   public static String getLastDayOfMonth(String yearMonth) {
      int year = Integer.parseInt(yearMonth.split("-")[0]); // 年
      int month = Integer.parseInt(yearMonth.split("-")[1]); // 月
      return getLastDayOfMonth(year, month);
   }
   /**
    * 获取指定年月的最后一天
    *
    * @param year
    * @param month
    * @return
    */
   public static String getLastDayOfMonth(int year, int month) {
      Calendar cal = Calendar.getInstance();
      // 设置年份
      cal.set(Calendar.YEAR, year);
      // 设置月份
      cal.set(Calendar.MONTH, month - 1);
      // 获取某月最大天数
      int lastDay = cal.getActualMaximum(Calendar.DATE);
      // 设置日历中月份的最大天数
      cal.set(Calendar.DAY_OF_MONTH, lastDay);
      // 格式化日期
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      return sdf.format(cal.getTime());
   }
   public static void main(String[] args) throws ParseException {
        System.out.println(getMonthSpace("2012-02", "2012-02"));