Преглед изворни кода

【修改】生成预约数据

zhuzhoutong пре 4 година
родитељ
комит
f4d93358b1

+ 23 - 0
framework-common/src/main/java/com/mrxu/framework/common/util/DateFunc.java

@@ -7,6 +7,8 @@ import java.util.Date;
 
 public class DateFunc {
 
+    public static final String DAY_FORMAT = "yyyy-MM-dd";
+
     public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
 
     /**
@@ -28,6 +30,11 @@ public class DateFunc {
 
     public static final SimpleDateFormat FORMAT = new SimpleDateFormat(TIME_FORMAT);
 
+    /**
+     * 时间格式
+     */
+    public static final SimpleDateFormat dayFormat = new SimpleDateFormat(DAY_FORMAT);
+
     /**
      * endFormat
      */
@@ -266,6 +273,19 @@ public class DateFunc {
         }
     }
 
+    /**
+     * 获取最近days日期
+     * @return String 日期
+     **/
+    public static Date getLastDay(int days,SimpleDateFormat dateFormat) {
+        try {
+            return dateFormat.parse(getLastNDayEnd(days));
+        } catch (ParseException e) {
+            e.printStackTrace();
+            throw new RuntimeException("获取最近days日结束日期异常:" + e.getMessage());
+        }
+    }
+
     public static void main(String[] args) {
         System.out.println(getLastDayEnd(23));
     }
@@ -440,4 +460,7 @@ public class DateFunc {
         return new SimpleDateFormat(resultFormat).format(time);
     }
 
+    public static String getDayStr(Date date) {
+        return getDateStr(date,DAY_FORMAT);
+    }
 }