我想创建一个简单的函数,得到2个PARAMS - 日期格式(DD/MM/YYYY,DD-MM-YYYY等)和以这种格式(1/4/2015,1-4-2015)的字符串。 首先是有没有办法检查格式是可以接受的SimpleDateFormat
如果dateInString
下一步就是今天,这里是我的代码:爪哇 - 检查日期格式是可以接受的,比较基础上的日期
public boolean checkDate(String dateInString, String format){
boolean result = false;
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
//parse the string to date
Date inputDate = dateFormat.parse(dateInString);
//check if the date is today using the format
//if the date is today then
result = true;
return result;
}
你读过的[SimpleDateFormat的]的Javadoc(https://docs.oracle.com/javase /8/docs/api/java/text/SimpleDateFormat.html)(特别是关于需要的格式构造的部分)? – 2016-03-03 12:30:54
是的,是有acceaptable日期的一部分吗? –
不,你没否则你就看到了“ - 如果给定的模式无效”部分 – 2016-03-03 12:33:59