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 strDate, SimpleDateFormat sdf)
is Date
boolean isDate = false;
try {
    sdf.parse(strDate);
    isDate = true;
} catch (Exception ex) {
    isDate = false;
return isDate;
...
booleanisDate(String strDate, String pattern)
is Date
try {
    parse(strDate, pattern);
    return true;
} catch (ParseException pe) {
    return false;
booleanisDate(String strDate, String pattern)
is Date
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
formatter.setLenient(false);
ParsePosition pos = new ParsePosition(0);
try {
    Date d = formatter.parse(strDate, pos);
    return true;
} catch (Exception e) {
    return false;
...
booleanisDate(String strDate, String pattern)
is Date
if (strDate == null || strDate.trim().length() <= 0)
    return false;
try {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.parse(strDate);
    return true;
} catch (ParseException e) {
    return false;
...
booleanisDate(String text, String pattern)
Validation method for date.
if (text == null || text.trim().isEmpty()) {
    return false;
try {
    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
    formatter.setLenient(false);
    formatter.parse(text);
} catch (Exception e) {
...
booleanisDate(String val, SimpleDateFormat formatter)
is Date
boolean valid = true;
try {
    Date date = formatter.parse(val);
    valid = null != date;
} catch (Exception ex) {
    valid = false;
return valid;
...
booleanisDate(String value, Locale locale)

Checks if the field is a valid date.

boolean bValid = true;
if (value != null) {
    try {
        DateFormat formatter = null;
        if (locale != null) {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
...
booleanisDateBefore(String date1)
is Date Before
try {
    String date2 = date1.substring(0, 10) + " 23:59:59";
    DateFormat df = DateFormat.getDateTimeInstance();
    return df.parse(date1).before(df.parse(date2));
} catch (ParseException e) {
    System.out.print("[SYS] " + e.getMessage());
    return false;
booleanisDateBefore(String date1, String date2)
is Date Before
try {
    return stringToDate(date1, "yyyy-MM-dd HH:mm:ss").before(stringToDate(date2, "yyyy-MM-dd HH:mm:ss"));
} catch (ParseException e) {
    System.out.print(e.getMessage());
return false;
booleanisDateBefore(String date1, String date2)
is Date Before
try {
    DateFormat df = DateFormat.getDateTimeInstance();
    return df.parse(date1).before(df.parse(date2));
} catch (ParseException e) {
    return false;