Java Date Value Check isDateValid(String date, Locale locale)

Here you can find the source of isDateValid(String date, Locale locale)

Description

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.

License

Apache License

Parameter

Parameter Description
date date passed as argument

Return

true if is a java date

Declaration

public static boolean isDateValid(String date, Locale locale) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;

import java.util.Locale;

public class Main {
    /**/*from   w  ww.  ja  va2  s  . com*/
     * 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. In this way we can use the
     * proper DateTime without changing the output.
     *
     * @param date date passed as argument
     * @return true if is a java date
     */
    public static boolean isDateValid(String date, Locale locale) {
        try {
            DateFormat format = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
            format.parse(date);
            return true;
        } catch (ParseException e) {
            return false;
        }
    }
}

Related

  1. isDateInRange(Date startDt, Date endDt, Date theDate)
  2. isDateInRange(Date toCheck, Date minRange, Date maxRange)
  3. IsDateOK(String date)
  4. isDateSortedAsc(List dates, String format)
  5. isDateTwo(String value)
  6. isDateValid(String dateString, String validFormat)
  7. isDateValid(String dateToCheck, String pattern)
  8. isDateValid(String dateToValidate)
  9. isDateValue(String inputString)