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

booleanisDateFormat(String dateString)
is Date Format
if (dateString.length() > TEMPLATE_DATEFORMAT.length())
    return false;
SimpleDateFormat sdf = new SimpleDateFormat(TEMPLATE_DATEFORMAT);
try {
    sdf.parse(dateString);
    return true;
} catch (ParseException e) {
    return false;
...
booleanisDateFormat(String str, String format)
is Date Format
if (hasText(str) || hasText(format)) {
    return false;
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setLenient(true);
Date date = sdf.parse(str);
String str2 = sdf.format(date);
if (!str.equals(str2)) {
...
booleanisDateFormatString(String s, String dateFormat, Locale locale)
Return true if a string can be parsed by the dateFormat with locale.
String dateformat = parseDateFormat(dateFormat);
SimpleDateFormat f = new SimpleDateFormat(dateformat, locale);
f.setLenient(false);
try {
    f.parse(s);
    return true;
} catch (Exception ex) {
    return false;
...
booleanisDateFormatValid(final String pattern)

Validates a DateFormat format String string .

boolean result = false;
try {
    new SimpleDateFormat(pattern);
    result = true; 
} catch (Throwable t) {
return result;
booleanisDateInRange(Date startDt, Date endDt, Date theDate)
is Date In Range
if (theDate.compareTo(startDt) == 0 || theDate.compareTo(endDt) == 0
        || (theDate.after(startDt) && theDate.before(endDt))) {
    return true;
} else {
    return false;
booleanisDateInRange(Date toCheck, Date minRange, Date maxRange)
is Date In Range
String toCheckStr = formatYmd(toCheck);
return ((minRange == null || toCheckStr.compareTo(formatYmd(minRange)) >= 0)
        && (maxRange == null || toCheckStr.compareTo(formatYmd(maxRange)) <= 0));
booleanIsDateOK(String date)
Returns true if the date is in format year/month/day, false if not
try {
    DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd");
    Date d = fmt.parse(date);
    return true;
} catch (Exception e) {
    return false;
booleanisDateSortedAsc(List dates, String format)
Determines if the list of dates is sorted in ascending order
boolean sorted = true;
Iterator<String> iList = dates.iterator();
String first = iList.next();
try {
    Date curr = new SimpleDateFormat(format, Locale.ENGLISH).parse(first);
    while (iList.hasNext()) {
        String next = iList.next();
        Date nextDate = new SimpleDateFormat(format, Locale.ENGLISH).parse(next);
...
booleanisDateTwo(String value)
qli comment the method "isDateTwo".
if (value != null) {
    try {
        String dateFormat = "yyyy-MM-dd";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
        Date dt = simpleDateFormat.parse(value);
        simpleDateFormat.format(dt);
        return true;
    } catch (ParseException pe) {
...
booleanisDateValid(String date, Locale locale)
Because the date passed as argument can be in java format, and because not all formats are compatible with joda-time, this method checks if the date string is valid with java.
try {
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
    format.parse(date);
    return true;
} catch (ParseException e) {
    return false;