Java Date Value Check isDate(String dateString)

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

Description

is Date

License

Apache License

Declaration

public static boolean isDate(String dateString) 

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 final String DEFAULT_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";

    public static boolean isDate(String dateString) {
        return tryParse(dateString);
    }/*from  ww  w  .j  a  v  a2s.c  o  m*/

    public static boolean tryParse(String dateString) {
        Date date = getDateTime(dateString);
        return (date == null ? false : true);
    }

    public static Date getDateTime(String dateString, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = sf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDateTime(String dateTimeString) {
        return getDateTime(dateTimeString, DEFAULT_FORMAT_DATETIME);
    }
}

Related

  1. isDate(final String dateString)
  2. isDate(final String strDate, final String pattern)
  3. isDate(Object object)
  4. isDate(String date)
  5. isDate(String dateStr, String dateFormat)
  6. isDate(String dttm, String format)
  7. isDate(String input)
  8. isDate(String input)
  9. isDate(String pattern, String text)