What is the use of “lenient ”?

2019-01-03 10:45发布

Here lenient is used in Java DateFormat. I checked the doc, but didn't get what it was saying.

Can any body please tell me what is the use of this lenient, with one real time example where we use it?

7条回答
We Are One
2楼-- · 2019-01-03 11:26

For example this:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
System.out.println(simpleDateFormat.parse("0"));
simpleDateFormat.setLenient(false);
System.out.println(simpleDateFormat.parse("0"));

results in:

Thu Jan 01 00:00:00 CET 1
Exception in thread "main" java.text.ParseException: Unparseable date: "0"
    at java.text.DateFormat.parse(Unknown Source)
    at net.java.quickcheck.generator.support.X.main(X.java:28)
查看更多
登录 后发表回答