/**
* 检查日期 YYYYMMDD
*/
public static boolean checkDate(String str){
boolean flag = false;
try {
String check = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229)(([0-1][0-9])|2[0-3])[0-5][0-9]";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(str);
flag = matcher.matches();
} catch (Exception e) {
e.printStackTrace();
flag = false;
}
return flag;
}
/**
* 检查时间 hhmmss
*/
public static boolean checkTime(String str){
boolean flag = false;
try {
String check = "(([01]\\d)|(2[0-3]))[0-5]\\d([0-5]\\d)?";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(str);
flag = matcher.matches();
} catch (Exception e) {
e.printStackTrace();
flag = false;
}
return flag;
}Java检查日期(YYYYMMDD)和时间(hhmmss)的格式
最新推荐文章于 2024-08-22 03:47:48 发布
本文介绍了一种使用正则表达式来验证日期(格式为YYYYMMDD)和时间(格式为hhmmss)的方法。通过Java代码实现,可以有效判断输入字符串是否符合标准日期和时间格式。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
280

被折叠的 条评论
为什么被折叠?



