Java Date Value Check isValidDate(String dateStr)

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

Description

is Valid Date

License

Open Source License

Declaration

public static boolean isValidDate(String dateStr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

public class Main {

    public static boolean isValidDate(String dateStr) {
        boolean isValid = false;
        if (dateStr == null || dateStr.length() <= 0) {
            return false;
        }//from   w  ww . j a v  a  2 s  .  c om
        String pattern = "yyyy-MM-dd";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            String date = sdf.format(sdf.parse(dateStr));
            if (date.equalsIgnoreCase(dateStr)) {
                isValid = true;
            }
        } catch (Exception e) {
            isValid = false;
        }
        return isValid;
    }
}

Related

  1. isValidDate(String createDate, String startDate)
  2. isValidDate(String date)
  3. isValidDate(String date)
  4. isValidDate(String date, String dateFormat)
  5. isValidDate(String date, String format)
  6. isValidDate(String dateString)
  7. isValidDate(String dateString)
  8. isValidDate(String dateString, String dateFormat)
  9. isValidDate(String dateString, String dateFormat)