Here you can find the source of isDate(final String strDate, final String pattern)
Parameter | Description |
---|---|
strDate | the str date |
pattern | the pattern |
public static boolean isDate(final String strDate, final String pattern)
//package com.java2s; /*/*w w w .jav a 2s . com*/ * Copyright 2002-2016 Jalal Kiswani. * * 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.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { /** * Checks if is date. * * @param strDate * the str date * @param pattern * the pattern * @return true, if is date */ public static boolean isDate(final String strDate, final String pattern) { try { parseDate(strDate, pattern); return true; } catch (final Exception e) { return false; } } /** * Parses the date. * * @param strDate * the str date * @param pattern * the pattern * @return the java.util. date * @throws ParseException * the parse exception */ public static java.util.Date parseDate(final String strDate, final String pattern) throws ParseException { final SimpleDateFormat parser = new SimpleDateFormat(pattern, Locale.US); final Date date = parser.parse(strDate); return date; } }