Beispiel #1
0
 /**
  * 将YYYYMMDD转换成Date日期
  *
  * @param date
  * @return
  * @throws BusinessException
  */
 public static Date transferDate(String date) {
   if (StringUtils.isEmpty(date) || date.length() != 8) {
     throw new RuntimeException("日期格式错误");
   }
   String con = "-";
   String yyyy = date.substring(0, 4);
   String mm = date.substring(4, 6);
   String dd = date.substring(6, 8);
   int month = Integer.parseInt(mm);
   int day = Integer.parseInt(dd);
   if (month < 1 || month > 12 || day < 1 || day > 31) {
     throw new RuntimeException("日期格式错误");
   }
   String str = yyyy + con + mm + con + dd;
   return DateUtil.getDate(str, DateUtil.YYYY_MM_DD_EN);
 }
Beispiel #2
0
 /**
  * 获取指定日期mins分钟后的一个(formatStr)的字符串
  *
  * @param date
  * @param mins
  * @param formatStr
  * @return
  */
 public static String getDateOfMin(String date, int mins, String formatStr) {
   Calendar now = Calendar.getInstance(TimeZone.getDefault());
   now.setTime(DateUtil.getDate(date, formatStr));
   now.add(Calendar.SECOND, mins * 60);
   return dateToDateString(now.getTime(), formatStr);
 }
Beispiel #3
0
 /**
  * 获取指定日期day天后的一个(formatStr)的字符串
  *
  * @param date
  * @param mins
  * @param formatStr
  * @return
  */
 public static String getDateOfDay(String date, int day, String formatStr) {
   Calendar now = Calendar.getInstance(TimeZone.getDefault());
   now.setTime(DateUtil.getDate(date, formatStr));
   now.add(Calendar.DATE, day);
   return dateToDateString(now.getTime(), formatStr);
 }
Beispiel #4
0
 /**
  * 获取指定日期mon月后的一个(formatStr)的字符串
  *
  * @param date
  * @param mins
  * @param formatStr
  * @return
  */
 public static String getDateOfMon(String date, int mon, String formatStr) {
   Calendar now = Calendar.getInstance(TimeZone.getDefault());
   now.setTime(DateUtil.getDate(date, formatStr));
   now.add(Calendar.MONTH, mon);
   return dateToDateString(now.getTime(), formatStr);
 }