File tree Expand file tree Collapse file tree 1 file changed +7
-22
lines changed
src/main/java/cn/jiguang/common/utils Expand file tree Collapse file tree 1 file changed +7
-22
lines changed Original file line number Diff line number Diff line change 11package cn .jiguang .common .utils ;
22
3-
43import java .text .ParseException ;
54import java .text .SimpleDateFormat ;
65
76public 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 }
You can’t perform that action at this time.
0 commit comments