Here you can find the source of isDateFormatValid(final String pattern)
Validates a DateFormat format String string .
Parameter | Description |
---|---|
pattern | The candidate String string to test. |
True
if the argument is a valid date format , and False
otherwise.
public static boolean isDateFormatValid(final String pattern)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; public class Main { /**//from w ww . ja v a 2 s. c om * <p> * Validates a {@link DateFormat format} {@link String string}. * </p> * * @param pattern * The candidate {@link String string} to test. * @return <code>True</code> if the argument is a valid {@link DateFormat * date format}, and <code>False</code> otherwise. */ public static boolean isDateFormatValid(final String pattern) { boolean result = false; try { new SimpleDateFormat(pattern); result = true; // if here, then format must be valid } catch (Throwable t) { } return result; } }