How to check if the Date conforms to a specific DateFormat without using Exception?
问题 I am aware that parse() can be used for knowing if the valid date conforms to a specific format. But that throws exception in case of a failure. I wanted just to verify if the date is of a specific format. Especially I need a boolean result from this comparison. How to achieve that in Java? 回答1: I am wondering why nobody here knows following standard validation using ParsePosition . Programming based on exception logic is more or less evil. SimpleDateFormat sdf = new SimpleDateFormat("MM/dd