DateFormat.setLenient(boolean lenient) has the following syntax.
public void setLenient(boolean lenient)
In the following code shows how to use DateFormat.setLenient(boolean lenient) method.
/* w ww . j a v a2s .c o m*/ import java.text.DateFormat; public class Main { public static boolean isValidDateStr(String date) throws Exception { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); df.setLenient(false); df.parse(date); return true; } public static void main(String[] args) throws Exception{ System.out.println(isValidDateStr("1900-13-12")); } }
The code above generates the following result.