Java Date Value Check isValidDate(String s)

Here you can find the source of isValidDate(String s)

Description

is Valid Date

License

LGPL

Declaration

public static boolean isValidDate(String s) 

Method Source Code


//package com.java2s;
/*//w w  w. j  a v  a 2s. com
 * OpenClinica is distributed under the
 * GNU Lesser General Public License (GNU LGPL).
    
 * For details see: http://www.openclinica.org/license
 * copyright 2003-2005 Akaza Research
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static boolean isValidDate(String s) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
        sdf.setLenient(false);
        try {
            java.util.Date date = sdf.parse(s);
            if (date.after(new java.util.Date())) {
                return false; // not a date in the past,for date of birth
            }
        } catch (ParseException fe) {
            return false; // format is wrong
        }

        return true;

    }
}

Related

  1. isValidDate(String dateString, String dateFormatPattern)
  2. isValidDate(String dateString, String format)
  3. isValidDate(String dt)
  4. isValidDate(String inDate)
  5. isValidDate(String psDt)
  6. isValidDate(String src, String format)
  7. isValidDate(String value)
  8. isValidDateFormat(String startDate)
  9. isValidDateFormat(String strDate, String dataFormat)