Java Date Value Check isDate(String strDate, String pattern)

Here you can find the source of isDate(String strDate, String pattern)

Description

is Date

License

Apache License

Declaration

public static boolean isDate(String strDate, String pattern) 

Method Source Code


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

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

import java.util.Date;

public class Main {

    public static boolean isDate(String strDate, String pattern) {
        try {//  ww w . j a  v  a2  s.c  o m
            parse(strDate, pattern);
            return true;
        } catch (ParseException pe) {
            return false;
        }
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. isDate(String str, String format)
  2. isDate(String str, String pattern)
  3. isDate(String strDate, SimpleDateFormat sdf)
  4. isDate(String strDate, String pattern)
  5. isDate(String strDate, String pattern)
  6. isDate(String text, String pattern)
  7. isDate(String val, SimpleDateFormat formatter)
  8. isDate(String value, Locale locale)
  9. isDateBefore(String date1)