Java Date Value Check isValidDate(String dateString, String dateFormatPattern)

Here you can find the source of isValidDate(String dateString, String dateFormatPattern)

Description

is Valid Date

License

Open Source License

Declaration

public static boolean isValidDate(String dateString, String dateFormatPattern) 

Method Source Code

//package com.java2s;
/**// w  w w.  ja  va2  s.co  m
 * Copyright (C) 2002-2005 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat();

    public static boolean isValidDate(String dateString, String dateFormatPattern) {

        Date validDate = null;
        synchronized (dateFormat) {
            try {
                dateFormat.applyPattern(dateFormatPattern);
                dateFormat.setLenient(false);
                validDate = dateFormat.parse(dateString);
            } catch (ParseException e) {
                // Ignore and return null
            }
        }
        return validDate != null;
    }
}

Related

  1. isValidDate(String dateString)
  2. isValidDate(String dateString, String dateFormat)
  3. isValidDate(String dateString, String dateFormat)
  4. isValidDate(String dateString, String dateFormat)
  5. isValidDate(String dateString, String dateFormat)
  6. isValidDate(String dateString, String format)
  7. isValidDate(String dt)
  8. isValidDate(String inDate)
  9. isValidDate(String psDt)