Java Utililty Methods Date Value Check

List of utility methods to do Date Value Check

Description

The list of methods to do Date Value Check are organized into topic(s).

Method

booleanisDate(String dttm, String format)
is Date
if (dttm == null || dttm.isEmpty() || format == null || format.isEmpty()) {
    return false;
if (format.replaceAll("'.+?'", "").indexOf("y") < 0) {
    format += "/yyyy";
    DateFormat formatter = new SimpleDateFormat("/yyyy");
    dttm += formatter.format(new Date());
DateFormat formatter = new SimpleDateFormat(format);
formatter.setLenient(false);
ParsePosition pos = new ParsePosition(0);
Date date = formatter.parse(dttm, pos);
if (date == null || pos.getErrorIndex() > 0) {
    return false;
if (pos.getIndex() != dttm.length()) {
    return false;
if (formatter.getCalendar().get(Calendar.YEAR) > 9999) {
    return false;
return true;
booleanisDate(String input)
is date
try {
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    Date d = sdf.parse(input);
    return true;
} catch (ParseException ex) {
    return false;
booleanisDate(String input)
is Date
if (input == null) {
    return false;
try {
    ymdOrYmdhms2Date(input);
} catch (ParseException e) {
    return false;
return true;
booleanisDate(String pattern, String text)
is Date
SimpleDateFormat sdf = getDateFormat(pattern);
try {
    sdf.parse(text);
    return true;
} catch (ParseException e) {
    return false;
booleanisDate(String s)
is Date
if (s != null) {
    if (s.matches("^\\d{4}([/.-])\\d{2}\\1\\d{2}$")) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.setLenient(false);
        return sdf.parse(s.replaceAll("[/.]", "-"), new ParsePosition(0)) != null;
    } else if (s.matches("^\\d{2}([/.-])\\d{2}\\1\\d{4}$")) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        sdf.setLenient(false);
...
booleanisDate(String str)
is Date
java.text.DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
try {
    sdf.setLenient(false);
    sdf.parse(str);
} catch (ParseException e) {
    return false;
return true;
...
booleanisDate(String str)
is Date
boolean isDate = false;
if (str == null)
    return isDate;
str = str.replaceAll("[/-]", "");
DateFormat df = new SimpleDateFormat(DATE_FORMAT_A);
try {
    df.parse(str);
    isDate = true;
...
booleanIsDate(String str)
Is Date
return IsDate("yy-mm-dd");
booleanisDate(String str, String format)
is Date
if (hasLength(str)) {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    formatter.setLenient(false);
    try {
        formatter.format(formatter.parse(str));
    } catch (Exception e) {
        return false;
    return true;
return false;
booleanisDate(String str, String pattern)
is Date
if (str == null) {
    return false;
if (pattern == null) {
    pattern = "YYYYMMDD";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
try {
...