|
@@ -1,5 +1,7 @@
|
|
|
package com.mrxu.framework.common.util;
|
|
package com.mrxu.framework.common.util;
|
|
|
|
|
|
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
|
+
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
@@ -404,21 +406,38 @@ public class DateFunc {
|
|
|
return getDateStr(date,TIME_FORMAT);
|
|
return getDateStr(date,TIME_FORMAT);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 项目默认日期格式
|
|
|
|
|
+ private final static SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
|
|
+ // 日期类型转换为字符串类型
|
|
|
|
|
+ public static String getTimeString(Date date) {
|
|
|
|
|
+ SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ if(date == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return sdt.format(date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// 验证 SimpleDateFormat 线程非安全
|
|
// 验证 SimpleDateFormat 线程非安全
|
|
|
- private static SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
- Date FOREVER_DATE = new Date(4092652799999L); // 2099-09-09 23:59:59
|
|
|
|
|
- Date NOW = new Date(1652429483663L); // 2022-05-13 16:11:23
|
|
|
|
|
|
|
+ SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ Date date1 = sdt.parse("2099-09-09 09:09:09");
|
|
|
|
|
+ Date date2 = sdt.parse("2088-08-08 08:08:08");
|
|
|
for(int i=0;i<10;i++) {
|
|
for(int i=0;i<10;i++) {
|
|
|
new Thread(new Runnable() {
|
|
new Thread(new Runnable() {
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- String foreverStr = sdt.format(FOREVER_DATE);
|
|
|
|
|
- if(!"2099-09-09 23:59:59".equals(foreverStr)) {
|
|
|
|
|
- System.out.println("forever error :"+foreverStr);
|
|
|
|
|
|
|
+ String date1Str = getTimeString(date1);
|
|
|
|
|
+ if(!"2099-09-09 09:09:09".equals(date1Str)) {
|
|
|
|
|
+ System.out.println("date1 error :" + date1Str);
|
|
|
}
|
|
}
|
|
|
- String nowStr = sdt.format(NOW);
|
|
|
|
|
- if(!"2022-05-13 16:11:23".equals(nowStr)) {
|
|
|
|
|
- System.out.println("now error :"+nowStr);
|
|
|
|
|
|
|
+ String date2Str = getTimeString(date2);
|
|
|
|
|
+ if(!"2088-08-08 08:08:08".equals(date2Str)) {
|
|
|
|
|
+ System.out.println("date2 error :" + date2Str);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}).start();
|
|
}).start();
|