Ver Fonte

代码合并

syh há 4 anos atrás
pai
commit
e38972b769

+ 31 - 29
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -72,12 +72,11 @@ public class DateUtils extends PropertyEditorSupport {
     private static final long MINUTE_IN_MILLIS = 60 * 1000L;
     private static final long SECOND_IN_MILLIS = 1000L;
 
-    // 指定模式的时间格式
-    private static SimpleDateFormat getSDFormat(String pattern) {
-        return new SimpleDateFormat(pattern);
+    public static String getNowHour(Date date) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
+        return simpleDateFormat.format(date);
     }
 
-
     public static Date getNowDate() throws ParseException {
         SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd");
         String nowDate = getNowDate("yyyy-MM-dd");
@@ -85,9 +84,13 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
 
-    public static String getNowHour(Date date){
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
-        return simpleDateFormat.format(date);
+    public static boolean compare(String beginDate, String nowDate) throws ParseException {
+        //如果想比较日期则写成"yyyy-MM-dd"就可以了
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //将字符串形式的时间转化为Date类型的时间
+        Date a = sdf.parse(beginDate);
+        Date b = sdf.parse(nowDate);
+        return a.before(b);
     }
 
 
@@ -105,6 +108,26 @@ public class DateUtils extends PropertyEditorSupport {
         return cal.get(Calendar.HOUR_OF_DAY);
     }
 
+    public static String getEndTime(String time) throws ParseException {
+        SimpleDateFormat smf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date parse = smf.parse(time);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(parse);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        calendar.add(Calendar.DAY_OF_MONTH, 1);
+        calendar.add(Calendar.SECOND, -1);
+        Date end = calendar.getTime();
+        String format = smf.format(end);
+        return format;
+    }
+
+    // 指定模式的时间格式
+    private static SimpleDateFormat getSDFormat(String pattern) {
+        return new SimpleDateFormat(pattern);
+    }
+
     /**
      * 指定模式的时间格式
      *
@@ -136,7 +159,7 @@ public class DateUtils extends PropertyEditorSupport {
             list.add(map);
         } else {
             while (DateUtils.compareDate(startDate, splitDate) < 0 || DateUtils.compareDate(startDate, endDate) <= 0) {
-                Map<String, String> map = new HashMap<String, String>();
+                Map<String, String> map = new HashMap<>();
                 map.put("startDate", splitDate);
                 map.put("endDate", endDate);
                 list.add(map);
@@ -158,27 +181,6 @@ public class DateUtils extends PropertyEditorSupport {
     public static Calendar getCalendar() {
         return Calendar.getInstance();
     }
-    public static boolean compare(String beginDate, String nowDate) throws ParseException {
-        //如果想比较日期则写成"yyyy-MM-dd"就可以了
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        //将字符串形式的时间转化为Date类型的时间
-        Date a = sdf.parse(beginDate);
-        Date b = sdf.parse(nowDate);
-        //Date类的一个方法,如果a早于b返回true,否则返回false
-        if (a.before(b)) {
-            return true;
-        } else {
-            return false;
-        }
-
-		/*
-		 * 如果你不喜欢用上面这个太流氓的方法,也可以根据将Date转换成毫秒
-		if(a.getTime()-b.getTime()<0)
-			return true;
-		else
-			return false;
-		*/
-    }
     /**
      * 指定毫秒数表示的日历
      *