Java Date Value Check isValidDate(String date)

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

Description

is Valid Date

License

Apache License

Declaration

public static boolean isValidDate(String date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public final static String DATE_FORMAT = "yyyy-MM-dd";

    public static boolean isValidDate(String date) {
        return isValidDateInternal(date, DATE_FORMAT);
    }/*from  www.  ja v  a  2  s .  c o  m*/

    private static boolean isValidDateInternal(String date, String dateFormat) {
        try {
            DateFormat df = new SimpleDateFormat(dateFormat);
            df.setLenient(false);
            df.parse(date);
            return true;
        } catch (ParseException e) {
            return false;
        }
    }
}

Related

  1. isValidDate(DateFormat sdf, String date)
  2. isValidDate(final String date, final String format, final boolean lenient)
  3. isValidDate(final String date, final String format, final Locale locale)
  4. isValidDate(String createDate, String startDate)
  5. isValidDate(String date)
  6. isValidDate(String date, String dateFormat)
  7. isValidDate(String date, String format)
  8. isValidDate(String dateStr)
  9. isValidDate(String dateString)