-
hello
i want to validate if the pattern of date format string is valid? such as "yyyy-MM-dd" is valid, but "oooo-oo-uu" is not valid, i know that i can valid it by constructor of SimpleDateFormat, something like:
new SimpleDateFormat(); if it is invalid, the exception will throw. but i think it looks not a good practise, i wonder if there are other ways?
thanks
-
try {
DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
dateFormat.setLenient( Boolean.FALSE );
dateFormat.parse( inputDate );
}catch ( ParseException ex ) {
// exception occurs if format is not valid.
}
-
thanks, but it seems you didn't understand my, what i want is to validate the "pattern" itself,but not if the date follow that pattern.