Here you can find the source of isDate(String strDate, String pattern)
public static boolean isDate(String strDate, String pattern)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>(); public static boolean isDate(String strDate, String pattern) { if (strDate == null || strDate.trim().length() <= 0) return false; try {/*w w w.ja v a2 s .c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.parse(strDate); return true; } catch (ParseException e) { return false; } } public static Date parse(String source, String pattern) { if (source == null) { return null; } Date date; try { date = getFormat(pattern).parse(source); } catch (ParseException e) { return null; } return date; } public static DateFormat getFormat(String pattern) { DateFormat format = DFS.get(pattern); if (format == null) { format = new SimpleDateFormat(pattern); DFS.put(pattern, format); } return format; } }