Skip to content

Commit 82eaf2d

Browse files
authored
Update TimeUtils.java
fix:方法内创建SimpleDateFormat
1 parent 8754449 commit 82eaf2d

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/main/java/cn/jiguang/common/utils/TimeUtils.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
11
package cn.jiguang.common.utils;
22

3-
43
import java.text.ParseException;
54
import java.text.SimpleDateFormat;
65

76
public class TimeUtils {
87

9-
private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
10-
@Override
11-
protected SimpleDateFormat initialValue() {
12-
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
13-
}
14-
};
15-
private static final ThreadLocal<SimpleDateFormat> TIME_ONLY_FORMAT = new ThreadLocal<SimpleDateFormat>() {
16-
@Override
17-
protected SimpleDateFormat initialValue() {
18-
return new SimpleDateFormat("HH:mm:ss");
19-
}
20-
};
21-
22-
static {
23-
DATE_FORMAT.get().setLenient(false);
24-
TIME_ONLY_FORMAT.get().setLenient(false);
25-
}
26-
278
public static boolean isDateFormat(String time) {
289
try {
29-
DATE_FORMAT.get().parse(time);
10+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
11+
simpleDateFormat.setLenient(false);
12+
simpleDateFormat.parse(time);
3013
} catch (ParseException e) {
3114
return false;
3215
}
3316
return true;
3417
}
3518

3619
public static boolean isTimeFormat(String time) {
37-
try{
38-
TIME_ONLY_FORMAT.get().parse(time);
20+
try {
21+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
22+
simpleDateFormat.setLenient(false);
23+
simpleDateFormat.parse(time);
3924
} catch (ParseException e) {
4025
return false;
4126
}

0 commit comments

Comments
 (0)