在开发过程中时间验证虽然不多用,但是还是有必要掌握的;
验证格式:
SimpleDateFormat sdf =
new
SimpleDateFormat(
"yyyy-MM-DD"
);
BufferedReader bf =
new
BufferedReader(
new
InputStreamReader(System.in));
String str =
null
;
System.out.println(
"Enter your Date:"
);
str = bf.readLine();//输入时间内容(字符串)
try
{
sdf.parse(str);
}
catch
(ParseException e) {
System.out.println(
"Data Format Error!"
);
}
时间: 2024-10-11 16:20:05