先用try,catch模块,在模块里用Date.parse("日期字符串")
这么试试,赞同就采纳吧
采用正则表达式验证
public boolean exec(String s) {
Pattern pattern = Pattern.compile("//(//d{4}//)-//d{2}-//d{2}");
Matcher matcher = pattern.matcher(s);
if (matcher.find()){
return true;
}else {
return false;
}
}
大概意思就是这样了,仅供参考!!
str=dateNow;
假设str存储的是一个日期;
判断格式
if (substr(str,5,6)<>'-' or substr(str,8,9)<>'-' ){
MessageBox.Show( "日期格式错误 ")}