how to validate the patttern of date format ?

Discussions

General J2EE: how to validate the patttern of date format ?

  1. how to validate the patttern of date format ? (2 messages)

    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
  2. 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. }
  3. 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.