Here you can find the source of isValidDate(final String date, final String format, final boolean lenient)
Parameter | Description |
---|---|
date | The Date as String |
format | The Format for the Date to parse |
lenient | Specify whether or not date/time interpretation is to be lenient. |
public static boolean isValidDate(final String date, final String format, final boolean lenient)
//package com.java2s; /**//from w w w. ja v a 2 s . co m * Copyright (C) 2007 Asterios Raptis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { /** * Checks if the Date is valid to convert. * * @param date * The Date as String * @param format * The Format for the Date to parse * @param lenient * Specify whether or not date/time interpretation is to be lenient. * @return True if the Date is valid otherwise false. */ public static boolean isValidDate(final String date, final String format, final boolean lenient) { boolean isValid = true; if (date == null || format == null || format.length() <= 0) { return false; } final DateFormat df = new SimpleDateFormat(format); df.setLenient(lenient); try { df.parse(date); } catch (final ParseException e) { isValid = false; } return isValid; } }