Java Date Value Check isValidateData(String val)

Here you can find the source of isValidateData(String val)

Description

is Validate Data

License

LGPL

Declaration

public static boolean isValidateData(String val) 

Method Source Code


//package com.java2s;
/*//from w  ww  .j a va 2s .  c  o  m
* Distributable under LGPL v3 license.
* See terms of license at https://github.com/Yunfeng/schotel/blob/master/LICENSE
*/

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static boolean isValidateData(String val) {
        try {
            convertToDate(val, "yyyy-MM-dd");
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public static Date convertToDate(String val, String format) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.parse(val);
    }

    public static Date convertToDate(String val) throws ParseException {
        return convertToDate(val, "yyyy-MM-dd");
    }
}

Related

  1. isDateValid(String date, Locale locale)
  2. isDateValid(String dateString, String validFormat)
  3. isDateValid(String dateToCheck, String pattern)
  4. isDateValid(String dateToValidate)
  5. isDateValue(String inputString)
  6. isValidDate(DateFormat sdf, String date)
  7. isValidDate(final String date, final String format, final boolean lenient)
  8. isValidDate(final String date, final String format, final Locale locale)
  9. isValidDate(String createDate, String startDate)