本文共 745 字,大约阅读时间需要 2 分钟。
public class Demo { public static final String[] patterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd","yyyy/MM/dd HH:mm:ss"}; //判断字符串是否为日期格式 public static boolean isDate(String param){ if(param==null) return false; try{ DateUtils.parseDate(param,patterns); }catch (ParseException e){ return false; } return true; } //判断日期字符串能否正确转换格式 public static Date isDate(String param, String pattern){ DateFormat format = new SimpleDateFormat(pattern); if(param==null) return null; try{ return format.parse(param); }catch (ParseException e){ return null; } }}
转载地址:http://vukai.baihongyu.com/