Here you can find the source of isValidDate(String inDate)
public static boolean isValidDate(String inDate)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; public class Main { private static List<SimpleDateFormat> dateFormats = new ArrayList<SimpleDateFormat>() { {//from w ww .j a v a2 s .c o m add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); add(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss")); add(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")); add(new SimpleDateFormat("yyyy-MM-dd")); add(new SimpleDateFormat("yyyy.MM.dd")); add(new SimpleDateFormat("yyyy/MM/dd")); } }; public static boolean isValidDate(String inDate) { Date date = null; for (SimpleDateFormat format : dateFormats) { format.setLenient(false); try { if (inDate.length() < 12 && format.toPattern().length() < 12) { date = format.parse(inDate.trim()); } else if (inDate.length() > 12 && format.toPattern().length() > 12) { date = format.parse(inDate.trim()); } } catch (ParseException e) { continue; } if (date != null) { break; } } if (date == null) { return false; } return true; } }