Java SQL Date Check isDate(String str)

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

Description

is Date

License

Open Source License

Declaration

public static boolean isDate(String str) 

Method Source Code


//package com.java2s;

import java.util.Calendar;
import com.google.common.base.Strings;

public class Main {
    public static final String DATE = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)";

    public static boolean isDate(String str) {
        if (!Strings.isNullOrEmpty(str) && str.matches(DATE)) {

            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(java.sql.Date.valueOf(str));
            cal2.setTimeInMillis(new java.util.Date().getTime());

            return Math.abs(cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)) <= 50;
        }/*from   www.  j  ava  2  s .  co  m*/

        return false;
    }
}

Related

  1. isDate(final PropertyDescriptor pd)
  2. isDate(int colType)
  3. isDate(int dataType)
  4. isDate(int dataType)
  5. isDate(Object obj)
  6. isDate(String val)
  7. isDateOneAfterDateTwo(Date dateOne, Date dateTwo)
  8. isDateType(Class targetType)
  9. isDateValue(Class inValueType)