Here you can find the source of isDate(String pattern, String text)
public static boolean isDate(String pattern, String text)
//package com.java2s; //License from project: LGPL import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; public class Main { private static final Map<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>(); public static boolean isDate(String pattern, String text) { SimpleDateFormat sdf = getDateFormat(pattern); try {/* ww w . j ava 2s . co m*/ sdf.parse(text); return true; } catch (ParseException e) { return false; } } public static SimpleDateFormat getDateFormat(String pattern) { synchronized (map) { SimpleDateFormat format = map.get(pattern); if (format == null) { format = new SimpleDateFormat(pattern); map.put(pattern, format); } return format; } } }