generated from root/miduo_server
服务器修改添加时间格式验证2
parent
45cdac4224
commit
9575b330f0
|
|
@ -8,6 +8,7 @@ import java.text.ParseException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 时间工具类
|
||||
|
|
@ -42,16 +43,14 @@ public class DateUtil {
|
|||
return format1.parse(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证时间格式是否是完整的 yyyy-MM-dd HH:mm:ss
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static boolean verifyDateStrFormat(String time){
|
||||
boolean result = false;
|
||||
try {
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
format.parse(time);
|
||||
result = true;
|
||||
}catch (Exception e){
|
||||
LOGGER.error("时间格式校验失败:{}",e.getMessage());
|
||||
}
|
||||
return result;
|
||||
String regular3="^(\\d{4})-([0-1]\\d)-([0-3]\\d)\\s([0-5]\\d):([0-5]\\d):([0-5]\\d)$";
|
||||
return Pattern.matches(regular3,time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue