Here you can find the source of isValidDate(String dateString, String dateFormatPattern)
public static boolean isValidDate(String dateString, String dateFormatPattern)
//package com.java2s; /**// w w w. ja va2 s.co m * Copyright (C) 2002-2005 WUZEWEN. All rights reserved. * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat dateFormat = new SimpleDateFormat(); public static boolean isValidDate(String dateString, String dateFormatPattern) { Date validDate = null; synchronized (dateFormat) { try { dateFormat.applyPattern(dateFormatPattern); dateFormat.setLenient(false); validDate = dateFormat.parse(dateString); } catch (ParseException e) { // Ignore and return null } } return validDate != null; } }