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

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

Description

is Date

License

LGPL

Declaration

public static boolean isDate(String pattern, String text) 

Method Source Code

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

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

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static final Map<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>();

    public static boolean isDate(String pattern, String text) {
        SimpleDateFormat sdf = getDateFormat(pattern);
        try {/* ww w  . j ava 2s .  co  m*/
            sdf.parse(text);
            return true;
        } catch (ParseException e) {
            return false;
        }
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        synchronized (map) {
            SimpleDateFormat format = map.get(pattern);
            if (format == null) {
                format = new SimpleDateFormat(pattern);
                map.put(pattern, format);
            }
            return format;
        }
    }
}

Related

  1. isDate(String dateStr, String dateFormat)
  2. isDate(String dateString)
  3. isDate(String dttm, String format)
  4. isDate(String input)
  5. isDate(String input)
  6. isDate(String s)
  7. isDate(String str)
  8. isDate(String str)
  9. IsDate(String str)