|
@@ -10,7 +10,7 @@ import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
*
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
-public class DateUtils
|
|
|
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|
|
{
|
|
|
public static String YYYY = "yyyy";
|
|
|
|
|
@@ -21,6 +21,11 @@ public class DateUtils
|
|
|
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
|
|
|
|
|
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
|
|
+
|
|
|
+ private static String[] parsePatterns = {
|
|
|
+ "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
|
|
+ "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
|
|
+ "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
|
|
|
|
|
/**
|
|
|
* 获取当前Date型日期
|
|
@@ -96,4 +101,23 @@ public class DateUtils
|
|
|
Date now = new Date();
|
|
|
return DateFormatUtils.format(now, "yyyyMMdd");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期型字符串转化为日期 格式
|
|
|
+ */
|
|
|
+ public static Date parseDate(Object str)
|
|
|
+ {
|
|
|
+ if (str == null)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return parseDate(str.toString(), parsePatterns);
|
|
|
+ }
|
|
|
+ catch (ParseException e)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|