Java Date Value Check isValidLongDateFormat(String strDate)

Here you can find the source of isValidLongDateFormat(String strDate)

Description

is Valid Long Date Format

License

Open Source License

Declaration

public static boolean isValidLongDateFormat(String strDate) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public final static String longFormat = "yyyyMMddHHmmss";

    public static boolean isValidLongDateFormat(String strDate) {
        if (strDate.length() != longFormat.length()) {
            return false;
        }//from   w  w w  . j ava2s . co m
        DateFormat df = createNewDateFormat(longFormat);

        try {
            df.parse(strDate);
        } catch (ParseException e) {
            return false;
        }

        return true;
    }

    public static boolean isValidLongDateFormat(String strDate, String delimiter) {
        String temp = strDate.replaceAll(delimiter, "");
        return isValidLongDateFormat(temp);
    }

    public static DateFormat createNewDateFormat(String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        df.setLenient(false);
        return df;
    }
}

Related

  1. isValidDateInternal(String date, String dateFormat)
  2. isValidDatePattern(String pattern)
  3. isValidDatePatterns(String dateStr, String patterns)
  4. isValidDateStr(String date, String format)
  5. isValidGameDate(String gameDate)
  6. isValidObjectModelDate(String aDate)
  7. isValidPattern(String dateString, String pattern)