Java Date Value Check isDate(final String dateString)

Here you can find the source of isDate(final String dateString)

Description

is Date

License

Open Source License

Declaration

public static boolean isDate(final String dateString) 

Method Source Code

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

public class Main {
    public static boolean isDate(final String dateString) {
        // return parseDate(dateString) != null;
        DateFormat formatter;/* w w w  .j av a  2 s.  c  om*/
        try {
            formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            formatter.parse(dateString);
            return true;
        } catch (final ParseException d) {
            try {
                formatter = new SimpleDateFormat(
                        "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
                formatter.parse(dateString);
                return true;
            } catch (final ParseException e) {
                try {
                    formatter = new SimpleDateFormat(
                            "yyyy-MM-dd'T'HH:mm:ss.SSS");
                    formatter.parse(dateString);
                    return true;
                } catch (final ParseException f) {
                    try {
                        formatter = new SimpleDateFormat(
                                "yyyy-MM-dd'T'HH:mm:ss");
                        formatter.parse(dateString);
                        return true;
                    } catch (final ParseException g) {
                        try {
                            formatter = new SimpleDateFormat("yyyy-MM-dd");
                            formatter.parse(dateString);
                            return true;
                        } catch (final ParseException h) {
                            try {
                                formatter = new SimpleDateFormat(
                                        "dd.MM.yyyy kk:mm");
                                formatter.parse(dateString);
                                return true;
                            } catch (final ParseException i) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
}

Related

  1. isData(long date)
  2. isDataOra(String date)
  3. isDate(final String date)
  4. isDate(final String date)
  5. isDate(final String strDate, final String pattern)
  6. isDate(Object object)
  7. isDate(String date)
  8. isDate(String dateStr, String dateFormat)