String str = ...; "2003-01-10";
java.text.SimpleDateFormat f[] = new SimpleDateFormat[]{
new SimpleDateFormat("yyyy-mm-dd"),
new SimpleDateFormat("hh:mm:ss"),
new SimpleDateFormat("..."),
};
boolean isDate = false;
for(int i = 0; i < f.length && !isDate; i++) {
try{
f[i].parse(str);
isDate = true;
}catch(Exception e){}
}
System.out.println(str+" is date?"+isDate);
java.text.SimpleDateFormat f[] = new SimpleDateFormat[]{
new SimpleDateFormat("yyyy-mm-dd"),
new SimpleDateFormat("hh:mm:ss"),
new SimpleDateFormat("..."),
};
boolean isDate = false;
for(int i = 0; i < f.length && !isDate; i++) {
try{
f[i].parse(str);
isDate = true;
}catch(Exception e){}
}
System.out.println(str+" is date?"+isDate);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货