Here you can find the source of isValidDatePatterns(String dateStr, String patterns)
public static boolean isValidDatePatterns(String dateStr, String patterns)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static String defaultPattern = "yyyy-MM-dd"; public static boolean isValidDatePatterns(String dateStr, String patterns) { if (patterns == null || "".equalsIgnoreCase(patterns) || patterns.length() < 1) { patterns = "yyyy-MM-dd;dd/MM/yyyy;yyyy/MM/dd;yyyy/M/d h:mm"; }//from w w w . j av a 2s . c o m boolean isValid = false; String[] patternArr = patterns.split(";"); for (int i = 0; i < patternArr.length; i++) { try { SimpleDateFormat sdf = new SimpleDateFormat(patternArr[i]); String date = sdf.format(sdf.parse(dateStr)); if (date.equalsIgnoreCase(dateStr)) { isValid = true; defaultPattern = patternArr[i]; break; } } catch (Exception e) { isValid = false; } } return isValid; } public static Date parse(String source, String format) throws ParseException { if (source == null) { return null; } DateFormat df = null; if (format != null) { df = new SimpleDateFormat(format); } else { df = DateFormat.getDateInstance(DateFormat.DEFAULT); } return df.parse(source); } }