Java Date Value Check isDate(String str, String format)

Here you can find the source of isDate(String str, String format)

Description

is Date

License

Open Source License

Declaration

public static boolean isDate(String str, String format) 

Method Source Code

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

import java.text.SimpleDateFormat;

public class Main {

    public static boolean isDate(String str, String format) {
        if (hasLength(str)) {
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            formatter.setLenient(false);
            try {
                formatter.format(formatter.parse(str));
            } catch (Exception e) {
                return false;
            }/*from   ww  w  .  j  av a  2 s  .c o  m*/
            return true;
        }
        return false;
    }

    public static boolean hasLength(String str) {
        return str != null && str.trim().length() > 0;
    }
}

Related

  1. isDate(String pattern, String text)
  2. isDate(String s)
  3. isDate(String str)
  4. isDate(String str)
  5. IsDate(String str)
  6. isDate(String str, String pattern)
  7. isDate(String strDate, SimpleDateFormat sdf)
  8. isDate(String strDate, String pattern)
  9. isDate(String strDate, String pattern)