public static boolean checkTime(String time) {
try {
String[] split = time.split(":");
if (Integer.parseInt(split[0]) > 23 || split[0].length() != 2) {
return false;
}
if (Integer.parseInt(split[1]) > 59 || split[1].length() != 2) {
return false;
}
if (Integer.parseInt(split[2]) > 59 || split[2].length() != 2) {
return false;
}
} catch (Exception e) {
//NumberFormatException or NullPointerException
return false;
}
return true;
}
很简单的代码 还是比较好用的 比正则表达式好些一哈哈
顺颂时祺
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)