Java Date Value Check isDateFormatValid(final String pattern)

Here you can find the source of isDateFormatValid(final String pattern)

Description

Validates a DateFormat format String string .

License

Open Source License

Parameter

Parameter Description
pattern The candidate String string to test.

Return

True if the argument is a valid date format , and False otherwise.

Declaration

public static boolean isDateFormatValid(final String pattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

public class Main {
    /**//from   w  ww  . ja  v  a  2 s. c om
     * <p>
     * Validates a {@link DateFormat format} {@link String string}.
     * </p>
     * 
     * @param pattern
     *            The candidate {@link String string} to test.
     * @return <code>True</code> if the argument is a valid {@link DateFormat
     *         date format}, and <code>False</code> otherwise.
     */
    public static boolean isDateFormatValid(final String pattern) {
        boolean result = false;
        try {
            new SimpleDateFormat(pattern);
            result = true; // if here, then format must be valid
        } catch (Throwable t) {
        }
        return result;
    }
}

Related

  1. isDateBefore(String date1, String date2)
  2. isDateBefore(String date1, String date2)
  3. isDateFormat(String dateString)
  4. isDateFormat(String str, String format)
  5. isDateFormatString(String s, String dateFormat, Locale locale)
  6. isDateInRange(Date startDt, Date endDt, Date theDate)
  7. isDateInRange(Date toCheck, Date minRange, Date maxRange)
  8. IsDateOK(String date)
  9. isDateSortedAsc(List dates, String format)