Java Date Value Check isDateValue(String inputString)

Here you can find the source of isDateValue(String inputString)

Description

DOC zqin Comment method "isDateValue".

License

Open Source License

Parameter

Parameter Description
inputString a parameter

Declaration

public static boolean isDateValue(String inputString) 

Method Source Code


//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class Main {
    /**/*from   w ww .  jav a 2  s . c o  m*/
     * DOC zqin Comment method "isDateValue".
     * 
     * @param inputString
     * @return
     */
    public static boolean isDateValue(String inputString) {

        if (!isEmpty(inputString)) {
            try {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
                df.setLenient(false);
                df.parse(inputString);
                return true;
            } catch (Exception e) {
                return false;
            }
        }

        return false;
    }

    /**
     * DOC Zqin Comment method "isEmpty".
     * 
     * @param strs
     * @return
     */
    public static boolean isEmpty(String... strs) {
        if (strs == null) {
            return false;
        }

        for (String str : strs) {
            if (str == null) {
                return true;
            } else if ("".equals(str.trim())) { //$NON-NLS-1$
                return true;
            }
        }

        return false;
    }
}

Related

  1. isDateTwo(String value)
  2. isDateValid(String date, Locale locale)
  3. isDateValid(String dateString, String validFormat)
  4. isDateValid(String dateToCheck, String pattern)
  5. isDateValid(String dateToValidate)
  6. isValidateData(String val)
  7. isValidDate(DateFormat sdf, String date)
  8. isValidDate(final String date, final String format, final boolean lenient)
  9. isValidDate(final String date, final String format, final Locale locale)